标签:
标签中ng-app,什么情况需要指定名称,什么时候又不需要呢?
1、ng-app=""
<div ng-app="" ng-controller=‘myCtr‘> {{name}} </div> <script> function myCtr ($scope){ $scope.name = ‘Jason‘; } var myCtr = function ($scope){ $scope.name = ‘Jason‘; } </script>
js中直接用函数定义控制器(不推荐)
2、ng-app="myApp"
<div ng-app="" ng-controller=‘myCtr‘> {{name}} </div> <script> var app = angular.module(‘myApp‘,[]); app.controller(‘myCtr‘,function($scope){ $scope.name=‘Jason‘; }); </script>
这种用module来声明,就需要在标签中的ng-app指定一个名称.
标签:
原文地址:http://www.cnblogs.com/aajonas/p/5891944.html