我试图有条件地建立一个模板。 我买了一些div和跨越k2plugin指令。 按照为PluginUi属性,我想在模板的末尾插入另一指令。 我的代码,随后,插值一切,但为PluginUi例如,最后一个div的结果:
<div {{pluginui}} width='300' height='420'></div>
{{为PluginUi}}是文字,而应该插值来触发其他指令。 有趣的是,如果我把{{为PluginUi}}在同一行(例如标签之间的其它部位,它被插。
什么我收到错了吗?
app.directive("k2plugin", function () {
return {
restrict: "A",
scope: true,
link: function (scope, elements, attrs) {
console.log ("creating plugin");
// this won't work immediatley. attribute pluginname will be undefined as soon as this is called.
scope.pluginname = "Loading...";
scope.pluginid = null;
// observe changes to interpolated attributes
// [...] observe name, id, width, height
attrs.$observe('pluginui', function(value) {
console.log('pluginui has changed value to ' + value);
scope.pluginui = attrs.pluginui + "viewport";
});
},
template: "<div>\
<div>\
<span>{{pluginname}}</span>\
<span ng-click=\"resize(pluginid)\">_</span> <span ng-click=\"remove(pluginid)\">X</span>\
</div>\
<div {{pluginui}} width='{{pluginwidth}}' height='{{pluginheight}}'></div>\
</div>",
replace: true,
};
});
app.directive("canvasviewport", function () {
return {
restrict: "A",
scope: true,
link: function (scope, elements, attrs) {
console.log ("creating canvas viewport");
},
template: "<canvas width='{{pluginwidth}}' height='{{pluginheight}}'></canvas>",
replace: true
};
});
app.directive("divviewport", function () {
return {
restrict: "A",
scope: true,
link: function (scope, elements, attrs) {
console.log ("creating div viewport");
},
template: "<div style=\"width='{{pluginwidth}}' height='{{pluginheight}}'\"></div>",
replace: true
};
});
app.directive("autoviewport", function () {
return {
restrict: "A",
scope: true,
link: function (scope, elements, attrs) {
console.log ("creating auto viewport");
},
template: "<canvas width='{{pluginwidth}}' height='{{pluginheight}}'></canvas>",
replace: true
};
});