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模板中? –