繁体   English   中英

指令未在角度视图中加载

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM