I have a webpage that runs well, but on a certain route, it would not load certain functions. For example, this is code:
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');
}
})
]);
This has the same behavior, la 1 works, not la 2:
myApp.controller('people', ['$scope', function($scope) {
console.log('la 1');
$scope.allPeople = function() {
console.log('la 2');
}
}]);
These are routes:
myApp.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: '../../templates/all.html',
controller: 'all'
})
.when('/people', {
templateUrl: '../../templates/people.html',
controller: 'people'
})
});
When I load https://www.website.com, and navigate to People tab, it loads list of people. But, when I load the page WHILE in the People tab, the page would load, but without the list: I see la 1 printed, not la 2.
How can I run the allPeople when refreshed from /people?