0
我已经给出了一个示例代码,我想给用户数组添加一个元素。当我控制台登录用户对象时,我得到一个包含1个元素的数组,但它有3个资源对象,一个promise和一个$ resolved属性。有人可以解释我在这里失踪的内容吗?资源操作的默认设置以角度返回,我该如何修改返回的资源?
/*@ngInject*/
constructor(User, Auth, $state, $uibModal, $scope) {
this.Auth = Auth;
this.$state = $state;
this.$uibModal = $uibModal;
this.$scope = $scope;
this.newUser = {name: "New User", email: "[email protected]", password: "gg"};
this.users = User.query();
this.users.push(this.newUser);
console.log(this.users);
this.$scope.$watch('this.user', function(newUser) {
console.log("entered watch");
var val = this.users.indexOf(newUser);
if(val == this.users.length - 1) {
this.openNewUser();
}
});
}
我试图做到这一点的成功里面函数,正如你所显示的,但它表示'this.users.push()'的'this'在它内部是未定义的。这里发生了什么,我该如何解决它? – Kindman
我的不好。我习惯es6。我已经更新了我的回答 –
其实我想在es6中使用它,但是我以前面的方式解决了范围问题。我试图解决它,但我不认为我理解范围问题。 – Kindman