[英]Directive not loading in angular view
I am a newbie to angular. 我是新手。 I have an index.html file and controller.js file as follows `
我有一个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>
` And this is controller.js `这是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'
};
});
I am trying to add a directive template from file test.html with markup 我正在尝试使用标记从文件test.html添加指令模板
<h1>Hi</h1>
But its not loading in the browser .I am getting error Error: $compile:tpload Error Loading Template in the browser console. 但是它没有加载到浏览器中。我收到错误错误:$ compile:tpload错误在浏览器控制台中加载模板。
Can you please tell what I am missing here? 你能告诉我我在这里想念的吗?
Looks like its a browser issue,It was not working in chrome and internet explorer.I tried the same code with Mozilla Firefox and it worked. 看起来像是浏览器问题,它在chrome和Internet Explorer中不起作用。我在Mozilla Firefox上尝试了相同的代码,并且可以正常工作。
Thanks everyone for your suggestions. 感谢大家的建议。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.