2015年5月3日 星期日

AngularJS 在HTML一開始的引入問題

開始學習AngularJS 並在網頁上引入ng-app時遇到一個奇怪的問題:

首先建一個indexApp & its controller
var app = angular.module('indexApp', []);
app.controller('IndexController', ['$scope', function($scope){}]);


再來在網頁上使用ng-app並代入所創建的app值:

<html ng-app="indexApp">
  <body ng-controller="IndexController">
  </body>
</html>

>>>>> 無法作用

後來改為:

<html ng-app>
  <body ng-app="indexApp" ng-controller="IndexController">
  </body>
</html>

>>>>> 可以作用


之後再改回去第一個那樣的寫法,卻又可以使用了!!
不知是為何阿....第一次使用不能帶值嗎!?


// end

沒有留言:

張貼留言