【发布时间】:2017-08-07 08:05:54
【问题描述】:
当我尝试在指令正文中转换日期时出现错误:
错误:[$compile:nonassign] 属性中的表达式“未定义” 与指令“[DIRECTIVENAME]”一起使用的 [ATTRIBUTENAME] 是 不可分配!
我使用的是 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>
【问题讨论】:
标签: javascript angularjs