我有两个角度函数,它们根据其他函数返回属性。当我只是连接属性时,这工作正常,但给了我一个'不可分配的表达式'错误。当我打电话给工厂虽然它什么都不返回。
案例1 - 有效(但会抛出不可分配的表达式错误)
HTML
<input type="text" class="form-control" id="inputClearCasePassword" ng-model="clearCasePassword()" readonly>
角度控制器
$scope.clearCasePassword = function(){
return $scope.model.property1 + $scope.today + $filter('uppercase')($scope.model.property2);
}
案例2 - 返回错误
HTML
<input type="text" class="form-control" id="inputencryptedPassword" ng-model="encryptedPassword()" readonly>
角度控制器
$scope.encryptedPassword = function(){
return encryptionRepository.HMACSHA1($scope.clearCasePassword, $scope.model.encryptionKey);
}
这是工厂的样子:
app.factory('encryptionRepository', function() {
return {
HMACSHA1: function(text, key) {
var encrypted = CryptoJS.HmacSHA1(text, key );
return CryptoJS.enc.Hex.stringify(encrypted);
}
};
});
答案 0 :(得分:0)
ng-model
必须是对象属性,它不能是表达式。想象一下,如果您编辑输入,它将保存您的值?
您需要的是首先将值分配给属性,然后在ng-model
$scope.password = value1 + value2 + value3;
<input ng-model="password" />
好的,我看到你在输入上使用readonly
。在这种情况下,您可以使用ng-value
代替ng-model
。