它是坏的申报NG-应用和NG-控制器上html标记? [英] Is it bad to declare ng-app and ng-controller on html tag?

查看:96
本文介绍了它是坏的申报NG-应用和NG-控制器上html标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它是不好的做法,同时声明 NG-应用 NG-控制器< HTML和GT; 标签

Is it bad practice to declare both ng-app and ng-controller on the <html> tag?

例如:&LT; HTML类=无JSNG-应用=对myAppNG控制器=MainCtrl&GT;

这被认为是不好的做法?我想控制&LT;标题&GT; 我的应用程序标签动态的,所以我要声明的 MainCtrl 早因为它的范围是在应用程序的其它部分重要。

Is this considered bad practice? I am trying to control the <title> tag of my application dynamically, so I want to declare the MainCtrl early as it's scope is important in the rest of the application.

然后我可以使用&LT;标题&GT; {{settings.title}}&LT; /标题&GT; MainCtrl 并有子控制器通过访问 $ $范围= parent.settings.title的Hello World;

Then I can use <title>{{settings.title}}</title> in the MainCtrl and have child controllers access it via $scope.$parent.settings.title = "hello world";

推荐答案

您应该能够通过 $窗口抽象访问并设置标题,从而不再需要穿上 HTML 标记的控制器。

You should be able to access and set the title via the $window abstraction, thus removing the need to put a controller on the html tag.

这篇关于它是坏的申报NG-应用和NG-控制器上html标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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