我試圖編寫一個指令來解碼和編碼一些信息。基本上我使用一個Int將5個二進制信息存儲在一個數據庫中(給每個位賦值16,8,4,2,1)。Angular Directive使用'='scope&controllerAs
我需要編輯數據的方式:作爲一個Int和位。但是我將它們連接起來存在很多問題,並且這些(通過使用controllerAs表示法)(故意)複雜化。
1)當我改變Int沒有改變位。這是因爲鏈接函數似乎只載入一次 - 如何在指令中更改模型更新信息?
<input ng-model="c.int" type="text" />
<testdir score="c.int"></testdir>
我的指令包括:
scope: {
score: '='
},
controller: function() {
var vm = this;
vm.recChange = function() {
// convert bits to score
}
},
controllerAs: 'd',
link: function(scope, elem, attrs) {
// convert score to bits
和轉換得分爲scope.recommendations
,這是一個陣列5位的鏈接功能。
2)當我改變位(並使控制器使用$ scope),Int會改變。但我找不到使用controllerAs的方法 - 鏈接功能使用scope
,而我的控制器需要使用d.
前綴。
template: "<label ng-repeat='(key, recommendation) in recommendations' class='checkbox-inline'>
// template: "<label ng-repeat='(key, recommendation) in d.recommendations' class='checkbox-inline'> \
大 - 這解決了第1部分,但留下一個問題 –
的第2部分請檢查我更新 – ryeballar
哇 - 謝謝。很高興這不是微不足道的 –