Is it bad to declare ng-app and ng-controller on html tag?

前端 未结 2 2016
醉酒成梦
醉酒成梦 2020-12-29 02:41

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

For example:

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-29 02:59

    I don't think there will be any problem so far. The only impact is the rootscope no more readable from html markup, because the controller scope is overriding it.

    For example,

    $rootScope.$id = 002 // rootscope from $rootscope service $("#parent").scope().$id =002 // rootscope scope get from element scope $("#child").scope().$id =003 // controller scope get from element scope

    when it comes to the same markup,

    $rootScope.$id = 002 // rootscope from $rootscope service $("#parent").scope().$id =003 // controller scope get from element scope

    Here you have no way to get rootscope from element scope, but who cares.

提交回复
热议问题