gpt4 book ai didi

angularjs - 'var vm = this;' 在 Angular Controller 中是什么意思?

转载 作者:行者123 更新时间:2023-12-03 10:50:21 26 4
gpt4 key购买 nike

我在 github 上浏览了一些东西,我看到在 controller.js 里面,有人放了以下内容:

function ImageController ($scope, $timeout) {
var vm = this;
}

这是做什么用的?

最佳答案

vm在这种情况下意味着 viewmodel .

这是一个快捷方式,所以不要写 this.someMethod()您可以使用 vm.someMethod() .

使用时很常见 Controller As语法,所以你不要使用 $scope意外地”。

另外,this关键字使用起来可能很麻烦,因为它可能会根据使用位置引用不同的内容。

关于angularjs - 'var vm = this;' 在 Angular Controller 中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33740308/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com