1
可能有人解釋我或指向一個文檔,它不會解釋以下問題: 我無法在link
函數中設置'@'映射屬性指示。然而,'='映射的屬性可以在指令的link
函數中設置爲特定值。 工作的例子可以發現 here in jsbin設置=和@屬性在角度指令的鏈接功能
我指的是下面的代碼:
directive('myDir', function() {
return {
scope: {
byValue: '@',
byRef: '='},
template: '<span>byValue: {{byValue}}<br>byRef: {{byRef}}</span>',
link: function(scope) {
scope.byValue = 'Custom Value set for byValue'; //this call is ignored!!!
scope.byRef = 'Custom Value set for byRef';
}
};
該指令將呈現:
byValue: myProp byRef: Custom Value set for byRef
感謝,並有一個愉快的一天!
Gabriel
感謝Muctadir的答案。我可以解決你的問題,但我仍然有問題。在我的例子中,我在'link'函數中設置了範圍的'byValue'屬性。因此,我期望在渲染視圖中設置'link'函數中的值。不幸的是,渲染的視圖顯示了從外部作用域映射的值。看起來,這個角度在'link'函數調用之後設置了一個'@'映射屬性的值。你能證實嗎? – Gabriel