I fixed some things.
http://plnkr.co/edit/5Zaln7QT2gETVcGiMdoW?p=preview
Js
var myMod = angular.module("myApp",[]).controller("MainController", function($scope){ $scope.myModel = {selectedId:null}; }).controller("DetailController",function($scope){ $scope.items = [1,2,3,4]; $scope.watchHitCount = 0; $scope.$watch('myModel.selectedId', function(newVal, oldVal){ console.log(newVal + " " + oldVal); $scope.watchHitCount++; },true); });
index.html
<body ng-app="myApp"> <div ng-controller="MainController"> <ng-include src="'detail.html'" ng-controller="DetailController"></ng-include> </div> </body>
.Html details
<pre>watch hit: {{watchHitCount}}</pre> <pre>selected value: {{myModel.selectedId}}</pre> <select ng-model="myModel.selectedId" ui-select2=""> <option></option> <option ng-repeat="item in items" value="{{item}}">{{item}}</option> </select>
He complained that he did not find the controller, so I configured it as usual with the name ng-app and the declared module on which the controllers are defined.
I also added an object to store the value in your model. It is bad practice to use the $ scope object as a model; instead, your area should reference the object that is your model.
shaunhusain Jul 22 '13 at 18:57 2013-07-22 18:57
source share