2016-06-17 25 views
1

テンプレートディレクティブが次のコードで動作していますが、テンプレートURLが機能していませんか?すべてのテンプレートディレクティブは動作していますが、templateUrlは動作していません。

<html> 
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script> 
    <body ng-app="myApp"> 
     <p><a href="#/">Main</a></p> 
     <a href="#red">Red</a> 
     <a href="#green">Green</a> 
     <a href="#blue">Blue</a> 
     <div ng-view> 
     </div> 
     <!--template is working but template url is not working--> 
     <script"> 
      var app = angular.module("myApp", ["ngRoute"]); 
      app.config(function($routeProvider) { 
       $routeProvider 
       .when("/", { 
        template : 'hello' 
       }) 
       .when("/red", { 
        template : 'hi' 
       }) 
       .when("/green", { 
        templateUrl : 'hello.html' 
       }) 
       .when("/blue", { 
        templateUrl : "blue.htm" 
       }); 
      }); 
     </script> 
     <p>Click on the links to navigate to "red.htm", "green.htm", "blue.htm", or back to "main.htm"</p> 
    </body> 
</html> 
+0

フォーマットあなたの質問のコード適切にしてください。 – Manatax

答えて

0

あなたはtemplateUrlを使用するための(Apacheの)のようなWebサーバを必要としています。

http://plnkr.co/edit/L4Hxf7KiiVuouPWRv4pl

var app = angular.module("myApp", ["ngRoute"]); 
app.config(function($routeProvider) { 
    $routeProvider 
    .when("/", { 
     template: 'hello' 
    }) 
    .when("/red", { 
     template: 'hi' 
    }) 
    .when("/green", { 
     templateUrl: 'hello.html' 
    }) 
    .when("/blue", { 
     templateUrl: 'blue.html' 
    }); 

}); 
0

まずあなたが<script"> -> <script>に構文エラーがあります。
2番目:テンションの拡張子を確認してくださいhtml & htm;あなたのコードの作業[OK]を、このファイル構造については
は:
enter image description here
enter image description here

+0

は角度jsブラウザに依存していますか?それはmozillaで動作しているが、chromeでは動作していないからです。 –

関連する問題