Angularjs 不使用$Scope从控制器角度更新厄运

Angularjs 不使用$Scope从控制器角度更新厄运,angularjs,controller,scope,Angularjs,Controller,Scope,我真的需要你的帮助。。。这次我一点也不知道 我想用我的控制器更新我的厄运,角度元素 angular.controller('UpdateController', function(){ var vm = this; vm.updateText = 'Text to Update'; vm.updateIt = function(){ vm.updateText = 'my new text'; } }); 例如: HTML代码: <div

我真的需要你的帮助。。。这次我一点也不知道

我想用我的控制器更新我的厄运,角度元素

angular.controller('UpdateController', function(){
    var vm = this;
    vm.updateText = 'Text to Update';

    vm.updateIt = function(){
        vm.updateText = 'my new text';
    }
});
例如:

HTML代码:

<div ng-controller="UpdateController as UC">
{{UC.updateText}}
<button ng-click="UC.updateIt()"/>
</div>
我试过:

angular.controller('UpdateController', function(){

var updateText = this;
updateText.newText = 'Text to Update'

this.updateIt = function(){
    updateText.newText = "my new text";
}
});
我还将HTML更改为{{UC.updateText.newText}}

但它不起作用,我可以在console.log()中看到我的所有更改; 我试过多种方法。正在使用监视(错误,摘要已在运行)。以及其他变量和调用

有人能告诉我怎么用“这个”吗

我不想不使用$scope,如果我使用$scope标记,它会毫无问题地更新,但我不想放弃使用“this.”标记。 另外,我不想使用element.angular或jQuery


谢谢

您应该可以只使用
this.updateText='mynewtext'
。但是,建议使用分配给该的变量,因为在控制器内部的功能中,该变量可能会发生变化

angular.controller('UpdateController', function(){
    var vm = this;
    vm.updateText = 'Text to Update';

    vm.updateIt = function(){
        vm.updateText = 'my new text';
    }
});

成功了!非常感谢。我只需要把我的函数放在同一个变量中!!