以下工作未定义我:对象属性在AngularJS
HTML:
{{user.uid}}
JS:
"use strict";
app.controller('Ctrl', function($scope, Auth) {
$scope.user = Auth.user;
});
但
HTML:
{{uid}}
JS:
app.controller('Ctrl', function($scope, Auth) {
$scope.uid = Auth.user.uid;
});
不起作用,这是因为Auth.user.uid是不确定的!这是为什么发生?为什么我们可以在视图内调用属性,但不在控制器内?如果我想在控制器中调用属性,应该怎么做?
'Auth.user'是否会返回一个承诺? – Claies
@Claies我的猜测是别的地方在异步填充'Auth.user'。这不会是一个承诺本身 – Phil
@Phil是的,就像'$ http'的承诺一样。无论如何,没有看到“Auth”的代码,我们只能猜测真正的问题。 – Claies