我正在尝试编写一个指令来解码和编码一些信息。基本上,我正在使用一个Int(为每个位赋值16、8、4、2、1)将5个二进制信息存储在数据库中。
我需要两种编辑数据的方式:作为Int和作为位。但是我遇到了很多问题,它们(故意)通过使用controllerAs符号进行复合。
1) 当我更改Int时,位没有任何变化。这是因为链接函数似乎只加载了一次 - 如何使模型的更改更新指令中的信息?
我需要两种编辑数据的方式:作为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'> \
vm.score
从指令中传递回父级 http://plnkr.co/edit/PEWAzuPGJJleQqKW21Ds?p=preview。 - Simon H$scope
,但我正在尝试弃用它。 - Simon H