jquery - Angular to fire on TextBox change -
i'm new angular , trying figure out. there may better way i'm doing. i'm open suggestions.
i have text box want use call service "onchange".
i have results section updated. section uses template.
what i'm trying combine use of js templates angular code clarity , other reasons.
the code i'm using (below) producing error looks like:
error: [$compile:ctreq] http://errors.angularjs.org/1.3.16/$compile/ctreq?p0=ngmodel&p1=ngchange... etc.
here's main html section:
<div ng-controller="sltsearchcontroller"> <input id="searchinput" type="text" ng-change="change()" ng-model="searchinput" /> </div> <div id="listcontent"></div>
here's html template:
<script id="brand-template" type="application/html-template"> <div id="listcontent" ng-controller="sltsearchcontroller"> <div class="radioform" ng-repeat="item in brandnames"> <div id="tier-checkcont-{{item.brandid}}" ng-controller="sltsearchcontroller"> <input name="{{item.brandname}}" id="brand-{{item.brandid}}" type="radio" value="{{item.brandname}}" /> <label id="tier-label-{{item.brandid}}" for="{{item.brandname}}"> {{item.brandname}} </label> </div> </div> </div> </script>
here's js:
var sltapp = angular.module('sltapp', []); sltapp.controller('sltsearchcontroller', ['$scope', '$http', function ($scope, $http) { //$scope.searchinput //not sure this, if $scope.change = function () { $http.get('[link web service]'). success(function (data) { alert('success'); $scope.brandnames = data; doresultswindowreplace(); }). error(function () { alert('fail'); }); }; }]); function doresultswindowreplace() { var resultstemplate = $('#brand-template').clone().html(); $('#listcontent').replacewith(resultstemplate); }
you have set ng-model in input in order use ng-change, if it's not defined error. use variable name example.
<input id="searchinput" type="text" ng-change="change()" ng-model="name"/>
Comments
Post a Comment