我有簡單的離子模板是這樣的:對同一控制器中另一個方法的離子調用不確定?
<ion-item class="range range-calm">Shift {{shiftval}}:
<input ng-change="shiftChange()" type="range" ng-model="shiftval" min="1" max="25">
</ion-item>
<span class="input-label">In</span>
<input type="text" ng-model="decripted" id="dec" ng-change="change()" />
</label>
<span class="input-label">Out</span>
<input type="text" ng-model="encripted" />
</label>
與控制器的邏輯是這樣的:
.controller('mylog', function($scope) {
var shiftval = (typeof shiftval === 'undefined') ? 13 : shiftval;
$scope.change = function(){
this.decripted = this.decripted.toUpperCase();
this.encripted = cezarCipher(this.decripted, shiftval);
};
$scope.shiftChange = function(){
shiftval = this.shiftval;
$scope.change();
};
})
的最後一行,我嘗試調用$scope.change();
簡單地觸發事件,並再次重新渲染文本我得到這樣的錯誤:
Cannot read property 'toUpperCase' of undefined
就行了.toUpperCase()在該fn中。
如果有人有想法如何克服這一點,我會非常感謝!
你需要使用$ scope.decripted。這個.decripted是undefined –
試過了,但是也失敗 –