2016-06-28 54 views
0

我已经写了一个简单的angularjs自定义指令,但我似乎错过了一些东西。该代码可在Angular JS指令不能按预期工作

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

<head> 
    <meta charset="utf-8" /> 
    <title>AngularJS Plunker</title> 
    <script data-require="[email protected]*" 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

您使用的角度错误的版本,包含脚本更改为:

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