angularjs - 将 $apply() 与组件一起使用

标签 angularjs

我正在尝试使用 $apply()使用 Angular 为 1.5 的组件,我收到的错误是 self.$apply不是函数。

viewTest.controller('viewTest', function ($location) {
    var self = this;
    self.$onInit = function (location) {
    self.$apply()
    }
});

最佳答案

使用申请需要$scope而不是 self .因为 $apply是 angular js $scope 函数,所以你不能通过 this 调用它

viewTest.controller('viewTest', function ($scope,$location) {
    var self = this;
    self.$onInit = function (location) {
    $scope.$apply()
    }
});

关于angularjs - 将 $apply() 与组件一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42326560/

相关文章:

javascript - 将 JSON 响应映射到 TypeScript 中的组件模型。

angularjs - 如何使用angularjs过滤表格中的数据

javascript - 纠正 Controller 不添加空值的问题

angularjs - Bootstrap 模态的简单 Angular 指令

javascript - 如何通过 Angular 2中的事件对象获取输入字段名称

javascript - AngularJS 中的 find 与 querySelector

javascript - Angular 到 Aurelia 的过渡——一些基本问题

javascript - 修补 Element.prototype.addEventListener 会破坏任何 Angular 2 应用程序

javascript - 将指令 Promise 作为用于 ng-options 的属性值传递会创建无限摘要循环

javascript - 将绑定(bind)传递给 Angular 组件中的 TemplateUrl