angularjs - Update model outside of controller -
just starting out on angular, not sure how update model out of controller, or in fact if have head around do. have autocomplete field based on ion.autocomplete
html
<span ng-controller="ionautocompletecontroller"> <label class="item item-input item-stacked-label"> <span class="input-label">item description</span> <ion-autocomplete ng-model="model" item-value-key="name" item-view-value-key="view" items-method="gettestitems(query)" multiple-select="false" placeholder="bread, milk, eggs etc .." items-clicked-method="itemsclicked(callback)"/> </span> <button class="button button-block button-royal" ng-click="scan()">scan</button> <div class="row"> <div class="col"><b>item name</b></div> <div class="col" ng-model="name"></div> </div>
javascript
var myapp = angular.module('myapp', ['ionic','ngcordova','ion-autocomplete']); myapp.config(['$ionicconfigprovider', function($ionicconfigprovider) { $ionicconfigprovider.tabs.position('bottom') }]); myapp.controller('ionautocompletecontroller', function ($scope,$http) { $scope.model = ""; $scope.callbackvaluemodel = ""; $scope.gettestitems = function (query) { console.log(query); return $http.get('http://192.168.100.100/myapp/products/' + query). success(function(data, status, headers, config) { console.log(data); }).error(function(data, status, headers, config) { console.log("something went wrong") }); }; $scope.itemsclicked = function (callback) { console.log(callback); $scope.name=callback.item.name; console.log(callback); $scope.callbackvaluemodel = callback; } });
what happening here autoselect grabbing data rest server , results place in autocomplete. when item selected callback
returned in json array. want callback
place in ng-model="name"
out of controller. or assume why not updating.
your ng-model="name"
binds $scope.name
in controller. when data returned rest call, set $scope.name = data
.
Comments
Post a Comment