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.
(我有一个控制器负责与API通信以更新用户的属性,名称,电子邮件等。每个用户都有一个'id'
,在查看个人资料页面时从服务器传递。)
I would like to pass this value to the AngularJS controller so it knows what the API entry point is for the current user.
(我想将此值传递给AngularJS控制器,以便它知道当前用户的API入口点是什么。)
I've tried passing the value in ng-controller
.(我试过传递ng-controller
的值。)
For example:(例如:)
function UserCtrl(id, $scope, $filter) {
$scope.connection = $resource('api.com/user/' + id)
and in the HTML
(并在HTML中)
<body ng-controller="UserCtrl({% id %})">
where {% id %}
print the id sent from the server.
(其中{% id %}
打印从服务器发送的id。)
but I get errors.(但我得到错误。)
What is the correct way to pass a value into a controller on its creation?
(在创建时将值传递给控制器??的正确方法是什么?)
ask by nickponline translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…