Passing Parameter With Ngroute
here is my angularroute.html
Solution 1:
Remove everything that's not needed from your route template. Only the content that you added in your body of the template is required.
That will be included by angular into ng-view with the controller that you have configured in your route. It's a partial and not a complete html file.
Also your route.js
code is not correct. You could create a module angular.module('route', []).controller('route1Controller', function(){...})
and use it as dependency in your app.
With-out the brackets like you did in your route.js
you're getting a module that's already defined.
Please have a look at your updated code below or in this fiddle.
varAngApp = angular.module('AngularApp', ['ngRoute'])
.controller('Route1Controller', Route1Controller)
.controller('Route2Controller', Route2Controller);
AngApp.config(function ($routeProvider) {
$routeProvider
.when('/Route1/:ID', {
templateUrl:'Route1.html',
controller:'Route1Controller'
})
.when('/Route2', {
templateUrl: 'Route2.html',
controller:'Route2Controller'
})
.otherwise({
redirectTo: '/'
});
});
functionRoute1Controller($scope, $routeParams) {
$scope.ID = $routeParams.ID;
}
functionRoute2Controller($scope) {
}
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular-route.js"></script><divng-app="AngularApp"><scripttype="text/ng-template"id="Route1.html">
Route1
{{ID}}
{{4+10}}
</script><scripttype="text/ng-template"id="Route2.html">
Route2
{{4+10}}
</script><p>Routing Explained</p><ahref="#Route1/100">Route1</a><br/><ahref="#Route2">Route2</a><divng-view></div></div>
Post a Comment for "Passing Parameter With Ngroute"