Tuna
Tuna

Reputation: 7

How to store autocomplete tags input value in scope variable to be sent to database in angularjs?

I am new to angularjs.I have an autocomplete tag in my html page.I need to store the value selected in a variable so that it can be sent to a database. Suggest a way to do it?

js
var app = angular.module("myApp",
  ['ui.bootstrap','ui.utils','ngTagsInput','ngMaterial', 'ngMessages', 
    'material.svgAssetsCache'
  ]);
  app.controller("myCtrl",function($scope, $http, $mdDialog) {      
     $scope.tags = [];

Upvotes: 0

Views: 314

Answers (1)

Muhammed Riyas
Muhammed Riyas

Reputation: 62

HTML

<tag-manager tags="tags"
           autocomplete="allTags"
           caption="Select tag "> </tag-manager>

JS

  var app = angular.module("myApp",['ui.bootstrap','ui.utils','ngTagsInput','ngMaterial', 'ngMessages', 
   'material.svgAssetsCache']);
  app.controller("myCtrl",function($scope, $http, $mdDialog) {        

     $scope.tags = [];
     $scope.allTags = ['item1','item2','item3','item4'];
  });

Here selected items will get stored in $scope.tags and this can be passed to your $http call.

Upvotes: 3

Related Questions