ngApp without using any specific module name

后端 未结 1 758
無奈伤痛
無奈伤痛 2020-12-19 08:48

Consider the piece of code below:

part of html file:


    
{{name}}
相关标签:
1条回答
  • 2020-12-19 09:39

    Angular, has this "auto-discover" feature, that allows it to look up controllers by their name if they are defined on the global scope.

    This feature is mainly intended for quick demos/prototypes/proof-of-concept snippets and not real-world applications.


    From Angular's Developer Guide:

    NOTE: Although Angular allows you to create Controller functions in the global scope, this is not recommended. In a real application you should use the .controller method of your Angular Module for your application [...]


    Regarding the empty ngApp, if there is no name specified, it only means that there is no module to assign controllers, directives, services to, but other than that everything works fine.

    0 讨论(0)
提交回复
热议问题