2016-03-26 25 views
0

有人可以幫助我,請不要服務於HomeController。它沒有內部打印文本在我的Home.html當我運行http://localhost/myangular/TemplateUrl不顯示home.html

的index.html

<!DOCTYPE html> 
<html ng-app="myApp"> 
    <head> 
     <meta charset="UTF-8"> 
     <title>Title</title> 
     <link rel="stylesheet" href="css/bootstrap.min.css"> 
    </head> 
    <body> 
     <div ng-view></div> 

     <!-- Include the AngularJS library --> 
     <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script> 
     <!-- Include main.js --> 
     <script src="js/main.js"></script> 
    </body> 
</html> 

main.js

var app = angular.module("myApp", []); 

app.config(function($routeProvider) { 
    $routeProvider 
     .when('/', { 
      templateUrl: "templates/home.html", 
      controller: 'HomeController' 
     }) 
     .otherwise({ 
      redirectTo: '/' 
     }); 
}); 

app.controller('HomeController', function($scope) { 

}); 

home.html的

<h1>hello home</h1> 

回答

1

主要問題,我要和你的代碼看到的是,你不加載ngRoute - 因爲AngularJS 1.2.0,ngRoute被分成它自己的模塊。

步驟來解決您的問題:

  • 添加ngRoute庫://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-route.min.js
  • 將其添加爲依賴關係:angular.module("myApp",["ngRoute"])
+0

它的工作,但爲什麼視頻教程,我其次是不使用ngRoute依賴? – jemz

+0

啊..我現在看到ngRoute是分開的。謝謝你 – jemz

+0

我剛剛編輯了我的答案。自AngularJS 1.2.0以來,ngRoute被分成了自己的模塊。 –

0

像這樣嘗試:

app.config(function($routeProvider){ 
    $routeProvider.when('/',{ 
     templateUrl:"/templates/home.html", 
     controller: 'HomeController' 
    }).otherwise({ redirectTo: '/'}); 
}); 

具有templateUrl的相對路徑。我只是假設這一點,我不熟悉的角度

+0

不幸的是沒有工作 – jemz