2017-06-20 50 views
2

我是角度的新手。 我有一個index.html文件和文件controller.js如下 `無法在角度視圖中加載的指令

<html> 

<head> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script> 
    <script src="controller.js"></script> 

</head> 

<body ng-app="testApp"> 

    <div ng-controller="appCtrl"> 
    Sample 1 :a ={{a}}</br> 
    Sample 1:b ={{b}}</br> 
    <input ng-model="a"> 
    <hr> 
    <div ng-controller="childCtrl"> 
     Sample 2: a ={{a}}</br> 
     <input ng-model="a"></br> 
     Sample 2 :b ={{b}}</br> 
     Sample 2: c ={{c}}</br> 
     Sample 2 :d ={{d}}</br> 
     <hr> 
    </div> 
    <div message></div> 
    </div> 

</body> 

</html> 

` 這是controller.js

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

app.controller("appCtrl", function($scope) { 

    $scope.a = 10; 
    $scope.b = 20; 
}); 



app.controller("childCtrl", function($scope) { 

    $scope.c = 30; 
    $scope.d = 40; 
}); 
    app.directive("message", function() { 
     return { 
     templateUrl: 'test.html', 
     restrict: 'A' 
     }; 
    }); 

我試圖從文件測試添加指令模板與標記

<h1>Hi</h1> 

.HTML但其在我。我得到錯誤錯誤的瀏覽器不加載:$編譯:tpload 在瀏覽器控制檯中加載模板時出錯。

你能說說我在這裏失蹤了嗎?

+0

如果'test.html' ?? –

+0

@Saurabh Agrawal它在index.js和controller.js存在的同一個文件夾中 –

+0

和'childCtrl' ?? –

回答

0

看起來像它的瀏覽器問題,它不是在鉻和Internet Explorer中工作。我嘗試了與Mozilla Firefox相同的代碼,它的工作。

謝謝大家的建議。