0
我正在處理具有相同指令的應用程序,但內容更改和模板取決於模塊中控制器的ID。如何在Angularjs中創建自定義指令,以改變其在應用程序中使用ID的狀態?
app.directive('glTranslate', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var key = element.text();
attrs.$observe('options', function(value) {
var options;
try {
options= JSON.parse(value);
element.text(I18n.t(key, options));
} catch (err) {
// SyntaxError maybe thrown as the options string is dynamically updated through Angular bindings
// and the options string may be momentarily be syntactically incorrect
console.log("Error parsing options: " + value + "\nError:"+ err.message + "\n");
}
});
}
};
});
份額一些代碼,所以我會建議做 –
這將有助於你幫我出的文檔。我們可以使用Id:鏈接後: –
官方文檔在https://docs.angularjs.org/api/ng/service/$compile#directive-definition-object沒有可以設置的「Id」屬性 - 它真的沒有意義。您能否添加一些關於您如何看待此功能的示例,例如給定一個ID,輸出應該是什麼樣子。我懷疑你需要在指令html中定製一些東西,或者創建不同的指令,而不是混淆指令_itself_。 – Rhumborl