0
我有一个运行良好的网页,但在某个路径上,它不会加载某些功能。例如,这是代码:Angular:页面加载后功能不运行
myApp.controller('people', ['$scope', function($scope) {
$scope.$watch('$viewContentLoaded', function(){
console.log('la 1');
$scope.allPeople = function() {
// This does not run when refreshed at https://www.website.com/people
console.log('la 2');
}
})
]);
此具有相同的行为,la 1
作品,而不是la 2
:
myApp.controller('people', ['$scope', function($scope) {
console.log('la 1');
$scope.allPeople = function() {
console.log('la 2');
}
}]);
这些路线:
myApp.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: '../../templates/all.html',
controller: 'all'
})
.when('/people', {
templateUrl: '../../templates/people.html',
controller: 'people'
})
});
当我加载https://www.website.com
和导航到People
选项卡,它会加载人员列表。但是,当我在People
选项卡中加载页面WHILE时,页面将加载,但没有列表:我看到la 1
已打印,而不是la 2
。
如何在从/people
更新时运行allPeople
?
你在使用什么路由模块? 告诉我们如何设置路线。 –
@eranotzap,完成 –
ok没有任何声明allPeople函数只声明它。 –