我们如何使用 angular-new-router 在 angular 1.4 中查看控制器内的表达式 [英] How can we watch expressions inside a controller in angular 1.4 using angular-new-router

查看:11
本文介绍了我们如何使用 angular-new-router 在 angular 1.4 中查看控制器内的表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我们无法在 Angular 1.4+ 中将 $scope 注入到控制器中,我们如何像过去使用 $scope.$watch 那样观察表达式?

Since we cannot inject $scope inside controllers in Angular 1.4+, how can we watch expressions the way we used to do with $scope.$watch?

尝试注入 $scope 可以看到 这里(无法实例化控制器"错误),教程告诉我们:

An attempt to inject $scope can be seen here ("Could not instantiate controller" error), and tutorials tells us that:

如果我们传递 $scope,Angular 将无法实例化控制器在里面.它定义了它的可观察属性.(来源)

Angular wont be able to instantiate the controller if we pass $scope in it. It defines its observable properties on this. (source)

推荐答案

我遇到了这个问题,需要一个 npm 包;暂时让团队中的每个人都从源代码构建是没有好处的.我们在 npm 上发布了一个临时包来解决这个问题:npm install loomio-angular-router@0.5.7

I ran into this and needed an npm package; no good having everyone on the team build from source for the time being. We released an interim package on npm that fixes this issue: npm install loomio-angular-router@0.5.7

注意:您可能需要将 ng-viewport 重命名为 ng-outlet 才能使临时包正常工作.

Note: you may need to rename ng-viewport to ng-outlet to get the interim package working.

这篇关于我们如何使用 angular-new-router 在 angular 1.4 中查看控制器内的表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆