[英]Directive not loading in angular view
我是新手。 我有一個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'
};
});
我正在嘗試使用標記從文件test.html添加指令模板
<h1>Hi</h1>
但是它沒有加載到瀏覽器中。我收到錯誤錯誤:$ compile:tpload錯誤在瀏覽器控制台中加載模板。
你能告訴我我在這里想念的嗎?
看起來像是瀏覽器問題,它在chrome和Internet Explorer中不起作用。我在Mozilla Firefox上嘗試了相同的代碼,並且可以正常工作。
感謝大家的建議。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.