angularjs - Scope refuses to update -
for reason unknown me, can't controller scope update view, though apply running , scope has been updated. know because when console.log(data) see been updated.
userlist directive should assign data.activeuser property on controller's scope. working, view not updating accordingly
link demo: http://jsbin.com/mojemiki/6/edit
var app = angular.module('app', []); app.controller('myctrl', function ($scope) { $scope.data = { users : [{ name : 'bob' },{ name : 'koko' }], activeuser : {} }; $scope.selectuser = function (user) { // console showing user data console.log(user); $scope.data.activeuser = user; console.log($scope.data.activeuser); // data.activeuser has been updated, view not. why that? // $scope.$apply() - not helping // because aleady running }; }); app.directive('userlist', function () { return { scope : { users : '=', onselect : '&' }, template : '<h3>in directive scope</h3>' + '<button ng-repeat="u in users" ng-click="onselect({ user : u })">set active user: {{u.name}}</button>' + '<br/><code>{{users}}</code>' }; });
the problem including angular.js twice (version 1.2.1 cloudflare cdn , version 1.2.14 google cdn) , causing kind of conflict. remove 1 of them , work.
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.js"></script>
Comments
Post a Comment