यह करने के लिए सरल तरीका अभिनय किया जाना है, इसी template
में ng-init
का उपयोग कर प्रकट होता है।
angular.module('demo', ['ngRoute'])
.config(['$routeProvider',
function($routeProvider) {
$routeProvider
.when('/linkOne', {
controller: 'LinkController',
template: '<h1 ng-init="functionOne()">Hello world</h1>'
})
.when('/linkTwo', {
controller: 'LinkController',
template: '<h1 ng-init="functionTwo()">Hello Stackoverflow</h1>'
});
}])
.controller('LinkController', ['$scope', function($scope) {
$scope.functionOne = function(){
console.log("Hello");
}
$scope.functionTwo = function(){
console.log("Hello world");
}
}]);
एचटीएमएल कोड:
<!DOCTYPE html>
<html ng-app="demo">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular.min.js"></script>
<script src="https://code.angularjs.org/1.4.6/angular-route.js"></script>
</head>
<body>
<a href="#linkOne">Link One</a>
<a href="#linkTwo">Link Two</a>
<div ng-view></div>
</body>
</html>
स्रोत
2016-08-11 08:03:29
आप की जाँच की थी इस एक http://stackoverflow.com/questions/16062434/angular-different-route-same-template-controller-different-loading-method या यह आप जो चाहते हैं उससे अलग है? –