你有没有给我们NG-控制器视图或可你只是声明在$ routeProvider? [英] Do you have to us ng-Controller in the view or can you just declare it in the $routeProvider?

查看:138
本文介绍了你有没有给我们NG-控制器视图或可你只是声明在$ routeProvider?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我意识到我没有使用过NG-控制器申报我的控制器的官方范围在HTML,但以前只在$ routeProvider提到它和所有似乎很好。

是否有任何人知道的任何缺点留下它是这样?只有定义和制作提及我的控制器在$ routeProvider?


解决方案

我会认为这是正确的,优势你做它的方式,因为它可以更好通过保持东西,在涉及您的视图和约束控制器的情况下一个地方。

只要记住,在路由定义提供控制器是基本相同,把一个 NG-控制器=MyCtrl包含您<$ c中的元素中$ C> NG-视图指令符合你的路线图。

另外,如果你需要更复杂的路由(如:层次视图和控制器),那么我会考虑看的 UI路由器改为使用 ngRoute

I recently realized I had not used ng-Controller to declare the official scope of my controller in the HTML but had only mentioned it in $routeProvider and all APPEARS to be well.

Does any one know any disadvantage to leaving it as such? Only defining and the making reference to my controller in the $routeProvider?

解决方案

I would consider it correct, and an advantage the way you have done it, because it better relates the context of your view and bound controller by keeping things in the one place.

Just bear in mind that providing your controller in the route definition is basically the same as putting an ng-controller="MyCtrl" inside the element containing your ng-view directive that matches your route view.

Also, if you need more complex routing (eg: hierarchical views and controllers), then I would consider looking at ui-router to use instead of ngRoute

这篇关于你有没有给我们NG-控制器视图或可你只是声明在$ routeProvider?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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