I have a controller responsible for communicating with an API to update properties of a user, name, email, etc. Each user has an 'id'
which is passed from the server when the profile page is viewed.
I would like to pass this value to the AngularJS controller so it knows what the API entry point is for the current user. I've tried passing the value in ng-controller
. For example:
function UserCtrl(id, $scope, $filter) {
$scope.connection = $resource('api.com/user/' + id)
and in the HTML
<body ng-controller="UserCtrl({% id %})">
where {% id %}
print the id sent from the server. but I get errors.
What is the correct way to pass a value into a controller on its creation?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…