I'm using angular and added a button in index.html:
<button ng-controller = "studentCtrl" ng-click="$emit('update')">refresh</button>
When clicked, the model has been updated but the view not, even $digest
has been executed. When I add the same button in the templateURL
of studentCtrl
, it works fine. I try to move the button to ng-view
div
but it still fails, so can anyone tell me the difference?
The templateURL
for studentCtrl
is
<tr ng-controller="studentCtrl" ng-repeat="student in students">
<td>{{student.name}}</td>
<td><button ng-click="$emit('update')">refresh</button></td>
</tr>
and the studentCtrl
is
.controller('studentCtrl', ['$scope', 'baseDataUrl', '$http', '$timeout',
function($scope, baseDataUrl, $http, $timeout) {
$scope.update = function() {
$http.get(baseDataUrl).then(function(res) {
$scope.students = res.data;
});
};
$scope.update();
//when switch to student app, get all students data first
$scope.$on("update", function() {
//for test
$scope.students = [];
});
}]);