How can we pass parameters to partial view in angularJs. I am new to angular ,I am following These tutorials for learning .This tutorial explain basic quite well but nothing about how can we send parameter to partial view.
e.g /addStudent?id=45
$routeProvider.
when('/addStudent', {
templateUrl: 'addStudent.htm',
controller: 'AddStudentController'
}).
when('/viewStudents', {
templateUrl: 'viewStudents.htm',
controller: 'ViewStudentsController'
})
You can define parameter in address definition and access it by $stateParams
controller parameter
when(url: '/new/:portfolioId',
templateUrl: 'new.html',
controller: function($scope, $stateParams) {
$scope.portfolioId = $stateParams.portfolioId;
}
)
Look here: http://benfoster.io/blog/ui-router-optional-parameters
The more "Angular way" to achieve that is by using the $routeParams
service.
Check the docs.
to pass parameter in route you can define parameter as :parameter
in you url
like :
$routeProvider.
when('/addStudent', {
templateUrl: 'addStudent.htm',
controller: 'AddStudentController'
}).
when('/viewStudents', {
templateUrl: 'viewStudents.htm',
controller: 'ViewStudentsController'
}).
when('/students/:id', {
templateUrl: 'studentsDetail.htm',
controller: 'studentsDetailController'
})
here url students/:id
has id as a parameter.
Here is angular doc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With