Angular JS指令未按预期工作

时间:2016-06-28 11:06:23

标签: angularjs angularjs-directive

我写了一个简单的angularjs自定义指令,但我似乎错过了一些东西。该代码可在

获得
<!DOCTYPE html>
<html ng-app="myApp">

<head>
  <meta charset="utf-8" />
  <title>AngularJS Plunker</title>
  <script data-require="angular.js@*" data-semver="2.0.0" src="https://code.angularjs.org/2.0.0-beta.6/angular2.min.js"></script>
  <link rel="stylesheet" href="style.css" />
  <script src="menuDirective.js"></script>
  <script src="script.js"></script>
</head>

<body>
  <hello-world></hello-world>
</body>

</html>

指令

     (function(){
  angular.module('helloWorld',[])
  .directive('helloWorld',helloWorld);
  function helloWorld()
  {
    return {
      replace:true,
      restrict: 'AE',
      template: '<h3>Hello World!!</h3>'
    }
  }
})();

应用

      (function()
{
  "use strict"
   angular.module("myApp",['helloWorld']);
})();

http://plnkr.co/edit/zywA3bazXzdd5lERYdxk

任何帮助都将受到高度赞赏

1 个答案:

答案 0 :(得分:1)

您使用的是错误的angular版本,请将包含的脚本更改为:

<script src="https://code.angularjs.org/1.5.7/angular.min.js"></script>
相关问题