感謝你們兩位,這對我幫助很大。
我已經相應地更改了我的方法。我不想直接在#之間添加網址。我打電話給一個服務,讓我找到鏈接文本和我創建的參考之間的對應關係。
我因此創建了一個參考:
referential.json
{
"lollianus_primae" : {
"link" : "lollianus",
"content" : "torvum renidens fundato pectore mansit inmobilis nec se incusare nec quemquam alium passus et tandem nec confessus nec confutatus..."
},
"nulla_suffragiorum" : {
"link" : "nullasuffragiorum",
"content" : "torvum renidens fundato pectore mansit inmobilis nec se incusare nec quemquam alium passus et tandem nec confessus nec confutatus..."
},
"exploratius" : {
"link" : "exploratius",
"content" : "torvum renidens fundato pectore mansit inmobilis nec se incusare nec quemquam alium passus et tandem nec confessus nec confutatus..."
},
}
然後創建其使得能夠格式化每個文本塊的指令(是一個跨度或一個鏈接,如果是這樣,我?添加addActionToLink指令給它)。
(function() {
'use strict';
angular
.module('project')
.directive('formatText', formatText);
/** @ngInject */
function formatText($compile) {
var directive = {
restrict: 'A',
replace:true,
scope : {
texte : '='
},
link: function (scope, elem, attrs) {
if (scope.texte.indexOf('_') !== -1){
// this is a link
var link = scope.texte;
var content = scope.texte.replace('_', ' ');
elem.replaceWith($compile('<a add-action-to-link id="'+link+'">' + content + "</a>")(scope));
} else {
elem.replaceWith($compile("<span>" + scope.texte + "</span>")(scope));
}
}
};
return directive;
}
})();
addActionToLink指令向元素添加可能的操作。 在情況下采取行動,它發送信息到負責打開的服務和餵養彈出
(function() {
'use strict';
angular
.module('project')
.directive(addActionToLink, addActionToLink);
/** @ngInject */
function addActionToLink(dimensionsService, DefinitionService) {
var directive = {
restrict: 'A',
link: function (scope, elem, attrs) {
if (dimensionsService.estUnFormatDesktop()) {
elem.bind("mouseover", function() {
console.log(attrs);
DefinitionService.recupereReferential (attrs.id).then(function (res) {
DefinitionService.ouverturePopupEttransmissionInfosSurCetteDefinition(res.data, attrs, elem[0]);
}) ;
});
} else {
elem.bind("click", function() {
console.log(attrs);
DefinitionService.recupereReferential (attrs.id).then(function (res) { DefinitionService.ouverturePopupEttransmissionInfosSurCetteDefinition (res.data, attrs, elem[0]);
});
});
}
}
};
return directive;
}
})();
這是模板的樣子:
<p>
<ng-bind ng-repeat="text in page.text track by $index" format-text texte="text"></ng-bind>
</p>
服務檢索信息和打開彈出窗口仍在建設中。 再一次,非常感謝你。我不再被困住了。