2015-08-24 41 views
1

我试图在我的应用程序中包含指令,但即使基本指令不呈现。我究竟做错了什么?角度指令不呈现

angularloader.js:

var main = angular.module('ngMain', []) 
.directive('myScrollable', function() { 
return { 
    restrict: 'AE', 
    template: '<h3>Hello World!!</h3>' 
}; 
}); 

我的HTML:

<html ng-app dir="auto"> 
<head> 
<meta name="viewport" content="width=device-width" /> 
<title>@Model.Title</title> 
<script src="/Scripts/Libs/angular.js"></script> 
<script src="/Scripts/Custom/angularloader.js"></script> 
</head> 
<body dir="auto"> 
<my-scrollable></my-scrollable> 
</body> 
</html> 

尝试也在使用标签或属性..

回答

2

你应该ng-app="moduleName"

使用模块名称如:

<html ng-app="ngMain" dir="auto"> 

,如果你在一个变量分配角模块,然后使用像波纹管变量:

var main = angular.module('ngMain', []); 
main.directive('myScrollable', function() { 
return { 
    restrict: 'AE', 
    template: '<h3>Hello Worlds!!</h3>' 
}; 
}); 

Working PLUNKER Link

+0

谢谢。 Iv'e添加了模块名称,但它仍然是: Iv'e试图将链接脚本从plunker链接,但它没有帮助.. – zanzamer

+0

什么是您的角度版本?尝试1.4.x –

+0

我正在使用最新的1.4.4。我也尝试过来自plunkr 1.4.3的脚本,但也一样。我使用铬44.0.2403.157米。 – zanzamer

0

你必须确定你的模块,但忘了在HTML中使用与NG-应用= “你的模块名称”。一个额外的东西,你不需要声明一个变量主代码将没有这个工作。

angular 
.module('myModule', []) 
.directive('myDir', function{ 
    your code 
});