我有一个CSS类
.container{
width:55%;
}
现在,我需要编写一条指令以根据某些条件更改width:82%。我的指令是这样的。
controls.directive('niMainContain', function () {
return {
require: '^niContainer',
restrict: 'E',
transclude: true,
replace: false,
templateUrl: 'Views/Templates/niMainContain.html',
compile: function (scope, iElement, iAttrs, iController) {
if (scope[0].parentElement.innerHTML.indexOf("ni-right-aside") == -1) {
$(".contaier").css({
'width': '82%'
});
}
}
};
});
Views / Templates / niMainContain.html模板包含“ .contaier”类。
When system link the directive it is unable to fulfill require. So there need to change '^' to '?' and then System works fine....
controls.directive('niMainContain', function () {
return {
require: '?niContainer',
restrict: 'E',
transclude: true,
replace: false,
templateUrl: 'Views/Templates/niMainContain.html',
link: function (scope, iElement, iAttrs, iController) {
if (iAttrs.$$element[0].parentElement.innerHTML.indexOf("ni-right-aside") == -1) {
$(".contaier").css({
'width': '82%'
});
}
}
};
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句