javascript - Filtering content of one controller with model in another (AngularJS) -
i have similar this:
<div ng-controller="controllera"> <input type="text" id="search_form" value="search" ng-model="searchmodel" /> </div> <div ng-controller="controllerb"> <ul> <li ng-repeat="item in items | filter:searchmodel">{{item}}</li> </ul> </div>
but when search in input bar, not impact list. how can create model 1 controller impact content of another?
thanks.
edit
controllera
, controllerb
exclusively isolated of each other , maintain way. if need share model other controller, how utilize $rootscope
that?
you can utilize service
share info between controllers. utilize factory feature angular has define service
.
here illustration found here , easy google search.
<!doctype html> <html ng-app="project"> <head> <title>angular: service example</title> <script src="http://code.angularjs.org/angular-1.0.1.js"></script> <script> var projectmodule = angular.module('project',[]); projectmodule.factory('theservice', function() { homecoming { thing : { x : 100 } }; }); function firstctrl($scope, theservice) { $scope.thing = theservice.thing; $scope.name = "first controller"; } function secondctrl($scope, theservice) { $scope.something = theservice.thing; $scope.name = "second controller!"; } </script> </head> <body> <div ng-controller="firstctrl"> <h2>{{name}}</h2> <input ng-model="thing.x"/> </div> <div ng-controller="secondctrl"> <h2>{{name}}</h2> <input ng-model="something.x"/> </div> </body> </html>
javascript angularjs angularjs-model
No comments:
Post a Comment