Abh*_*ore 1 javascript angularjs angularjs-directive angular-directive
我是AngularJs的新手.我试图调用自定义指令但它没有被调用.
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="customDirective.js"></script>
</head>
<body>
<div ng-app="app">
<div ng-controller="MyController as ctrl">
<testingDirective></testingDirective>
{{ctrl.test}}
</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
我的javascript文件看起来像:
var app=angular.module('app',[]);
app.controller('MyController',[function(){
var self=this;
self.test='no';
}]);
app.directive('testingDirective',function(){
return{
restrict:'AE',
replace:true,
template:'<h1>Hello World Test</h1>'
};
});Run Code Online (Sandbox Code Playgroud)
指示:
app.directive('testingDirective',function(){});
Run Code Online (Sandbox Code Playgroud)
HTML用法:
<testing-directive></testing-directive>
Run Code Online (Sandbox Code Playgroud)
必须使用连字符调用Camel cased指令名称.例如,如果您有一个名为的指令myDirective,您将在标记中使用它<my-directive></my-directive>.