有时,标签中只要写ng-app,而有时却要用ng-app=”MyApp”之类的带具体值的写法,那两者区别在哪呢?
- 如果在js文件中的写法是直接用函数定义controller,例如:
var mycontroller = function($scope){
$scope.msg = 'hello';
}
那么在html中只需要用ng-app声明即可;
- 如果在js文件中是用module的方式来声明controller,例如:
var app = angular.module('MyApp', []);
app.controller('mycontroller ',function($scope){
$scope.msg = 'hello';
});
那么在html中就要声明ng-app=”MyApp”,否则是无法使用mycontroller的。