![](/img/trans.png)
[英]AngularJS - Why attributes of a directive does not work inside another directive?
[英]Why does this angularjs directive not work?
我很難嘗試遵循AngularJS指令的教程。 我一直無法在代碼中找到任何語法錯誤,我甚至嘗試添加jQuery。
main.js
var app = angular.module("app", []);
app.directive = ("enter", function () {
return function (scope, element) {
element.bind("mouseenter", function () {
console.log("I'm inside of you!");
});
}
});
ng.php
<body ng-app="app">
<div enter>I'm content!</div>
</body>
AngularJS和main.js都正確鏈接。
沒有報告控制台錯誤。
我錯過了什么?
app.directive
是一個函數,而不是屬性。
你在哪里:
app.directive = ('enter'...
應該:
app.directive('enter', function() ...)
所以你調用函數來注冊一個指令,而不是覆蓋一個賦值,這樣你就再也不能有任何指令了。 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.