【发布时间】:2018-01-04 11:25:53
【问题描述】:
这是我的html
<div ng-controller="simpleAppCtrl">
<p custom-directive ></p>
</div>
这是我的 js
angular.module("simpleApp", [])
.directive("customDirective", ()=>{
return (scope, element,attributes)=>{
element.css("width","100px");
element.css("border","2px solid red");
element.css("height","100px");
element.style.height = "500px";
}
})
.controller("simpleAppCtrl", $scope =>{
});
所以我使用 jqLite .css 方法向指令中的元素添加了一些样式,并且它起作用了,但是使用 Javascript STYLE 方法添加样式会返回一个错误,指出 STYLE 未定义。同样在指令中我不能在元素上使用 APPENCHILD 方法,但我可以使用 APPEND (这又是 jqLite 方法)。那么为什么我们不能使用大多数 JS 普通函数而需要使用 jquery 呢?
【问题讨论】:
标签: javascript jquery css angularjs