gpt4 book ai didi

javascript - 错误: [$compile:nonassign] Expression 'undefined' in attribute [ATTRIBUTENAME] used with directive '[DIRECTIVENAME]' is non-assignable?

转载 作者:行者123 更新时间:2023-12-03 04:46:58 24 4
gpt4 key购买 nike

当我尝试在指令体内转换日期时,出现错误:

Error: [$compile:nonassign] Expression 'undefined' in attribute [ATTRIBUTENAME] used with directive '[DIRECTIVENAME]' is non-assignable!

我使用的是 Angular 版本 1.4.14

预期结果:在我的模板指令中将返回类名 -

div class="news-block-container sm-padding-right"

什么可能导致此问题?谢谢您的回答

这是我的代码示例:

'use strict';

angular.module('test.directives')
.directive('test', function () {
var templatePath = "/views/templates/testTemplate.tmpl.html";
return {
restrict: 'E',
scope: {
position: '=',
},
templateUrl: templatePath,
link: function (scope, element, attrs) {
scope.$watch('position', function () {
if (scope.position === "left") {
scope.position = "sm-padding-right";
}
else {
scope.position = "sm-padding-left";
}
});
}
}

});
view - directive usage
<test-template position="'left'"></test-template>



//!TEMPLATE! - testTemplate
<div>
<a href="{{#}}">
<div class="news-block-container {{position}}">
</div>
</a>
</div>

最佳答案

只需使用 ng-class动态分配类的指令

<div>
<a href="{{#}}">
<div class="news-block-container" ng-class="position">
</div>
</a>
</div>

更改angular.module('test.directives')

到此angular.module('test.directives',[])

同时删除模板中哈希周围的大括号

更改<a href="{{#}}">

到此<a href="#">

关于javascript - 错误: [$compile:nonassign] Expression 'undefined' in attribute [ATTRIBUTENAME] used with directive '[DIRECTIVENAME]' is non-assignable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42829166/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com