2016-03-26 4 views
0

誰かが私に助けてくれますか?ホームコントローラーには対応していません。それは私が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ライブラリを追加します。//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-route.min.js
  • 依存関係として追加:angular.module("myApp",["ngRoute"])
+0

動作しません続いてngRoute依存関係を使用していませんか? – jemz

+0

ああ。私は今、ngRouteが分かれているのを見ています。ありがとうございます – jemz

+0

私はちょうど私の答えを編集しました。 ngRouteは、AngularJS 1.2.0以降、独自のモジュールに分けられました。 –

0

を実行したときに、私のHome.htmlに内部テキストを印刷しませんでした次のように試してください:

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

(templateUrlの相対パス) AngularJS 1.2.0以降、ngRouteを分けている - 私はちょうど私が角度

私はあなたのコードを見ている 主な問題あなたは ngRouteをロードしていないということです
+0

は、残念ながら、それが働いていますが、なぜ、私のビデオチュートリアルがある – jemz

関連する問題