我有一个定制指令:
<custom-directive style='height: {{window.innerHeight + "px"}}'></custom-directive>
myApp.directive('customDirective', function(){
return {
restrict: 'E',
templateUrl: '/views/controls/customTemplate.html'
};
});因此,表达式style='height: {{window.innerWidth + "px"}}'不起作用。应用程序只是忽略了它。怎么让它起作用?
发布于 2016-03-14 07:12:48
在指令中编写一个链接函数,其中您将获得指令元素,并使用它作为参数来更改元素的css。
比如,如果你想改变指令文字的颜色,就像这样-
link: function(scope, elem, attr) {
elem.css('color','red');
}Diective
myApp.directive('customDirective', function(){
return {
restrict: 'E',
templateUrl: '/views/controls/customTemplate.html',
link: function(scope, elem, attr) {
elem.css('color','red');
}
};
});https://stackoverflow.com/questions/35980948
复制相似问题