我像这样加载我的控制器:
$routeProvider
.when('/login', {
templateUrl : 'js/scripts/views/login.html',
controller: 'loginCont'
})工作正常。我决定在login.html中添加一个directive。如下所示:
<h1>I am login here! {{message}} </h1> //message updates from controller
<div loginDir>Testing</div> //css not applied最后,我将loginDir.js添加到我的main.html中。
下面是我的loginDir函数:
'use strict';
angular.module('myNewApp')
.directive('loginDir', function () {
return function (scope, element, attrs) {
return {
restrict:'A',
link : function () {
console.log("link called", element); //not consoling
element.css({border:'1px solid red'});
}
}
}
});有人知道我哪里做错了吗?
发布于 2015-04-21 20:42:24
发布于 2015-04-21 22:19:44
像工厂函数一样,我错误地返回了一个函数,而不是返回一个对象。这是我的mupdate:
angular.module('myNewApp')
.directive('loginDir', function () {
return function (scope, element, attrs) { //wrong! need to remove
return {
restrict:'A',
link : function () {
console.log("link called", element); //not consoling
element.css({border:'1px solid red'});
}
}
} //need to remove.
});https://stackoverflow.com/questions/29772494
复制相似问题