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函數只聲明它。 –