1
我有一个具有替换自定义指令的div。replaceWith不适用于div-include
<div class="timeline" layout="row" ng-repeat="event in ::vm.events">
<div replace-with='{{event.content}}'></div>
</div>
这是我的指令:
(function() {
'use strict';
angular
.module('app')
.directive('replaceWith', replaceWith);
/* @ngInject */
function replaceWith() {
// Usage:
//
// Creates:
//
var directive = {
link: link,
restrict: 'A'
};
return directive;
function link(scope, element, attrs) {
attrs.$observe('replaceWith', function (value) {
if (value) {
element.replaceWith(angular.isUndefined(value) ? '' : value);
}
});
}
}
})();
我从那里我得到的内容数据控制器:
vm.templateUrl = "scripts/controllers/sample.content.html";
vm.events = [{
title: 'Title1',
subtitle: '',
date: '6/6/2016',
image: 'assets/avatar-5.png',
content: '<div ng-include="vm.templateUrl"></div>',
palette: ''
}]
这里我的分度代替,用属性没有得到与NG更换-include template.but当我硬编码我的内容数据如content:<p>Sample Data</p>
它的工作。有人可以帮助我这个。
尝试'(文件)。就绪(函数(){ }'而不是'(function()' – BradTheBrutalitist
@BradTheBrutalitist:我没有明白你的意思,你正在谈论的是哪一个函数。 – Venkat
出于好奇,为什么你需要一个指令呢?难道你不能简单地用ng -include在HTML模板中? –