我有一個ng-model
我正在處理一個小問題。ng模型問題的邏輯
首先,我將展示部分,其中ng-model
工作正常
<input type="text"
ng-model="slip.risk"
ng-change="riskWinCalculations(slip, 'RISKSTRAIGHT')">
<input type="text"
ng-model="slip.win"
ng-change="riskWinCalculations(slip, 'WINSTRAIGHT')">
<strong>To Win: </strong>{{straightTotalWin | currency}}
<strong>Total Stake: </strong>{{straightTotalStake | currency}}
現在所在的ng-model
未在該控制器爲我工作
<input type="text"
ng-change="riskWinCalculations(null, 'RISKPARLAY')"
ng-model="riskParlay">
<strong>To Win: </strong>{{winParlay | currency}}
<strong>Total Stake: </strong>{{riskParlay | currency}}
的HTML,你會看到一個名爲功能applyParlayRisk
這是給我的問題和其他功能riskWinCalculations
案件RISKPARLAY
也給我的問題,其餘的,他們都像一個魅力
applyStraightRisk = function(slip) {
var moneyLine = _.result(_.find(slip.lines, {isSelected: '1'}), 'moneyLine');
slip.win = RiskWikCalculations.calculateStraightBet(slip.risk, parseFloat(moneyLine, 10), true);
},
applyStraightWin = function(slip) {
var moneyLine = _.result(_.find(slip.lines, {isSelected: '1'}), 'moneyLine');
slip.risk = RiskWikCalculations.calculateStraightBet(slip.win, parseFloat(moneyLine, 10), false);
},
applyParlayRisk = function(parlay, riskParlay) {
$scope.riskParlay = riskParlay;
console.log($scope.riskParlay);
//this logs UNDEFINED
$scope.winParlay = riskParlay * (parlay.payoutProportion || 4.5);
},
sumStraightStakes = function(betSlip) {
var totalStake = 0,
totalWin = 0;
_.each(betSlip, function(slip) {
if (slip.risk) {
totalStake += parseFloat(slip.risk, 10);
}
if (slip.win) {
totalWin += parseFloat(slip.win, 10);
}
});
$scope.straightTotalStake = totalStake;
$scope.straightTotalWin = totalWin;
};
$scope.riskAll = 0;
$scope.winAll = 0;
$scope.riskWinCalculations = function(slip, type) {
switch (type) {
case 'RISKSTRAIGHT':
applyStraightRisk(slip, slip.risk);
break;
case 'WINSTRAIGHT':
applyStraightWin(slip, slip.win);
break;
case 'RISKPARLAY':
applyParlayRisk($scope.currentParlay, $scope.riskParlay);
break;
}
sumStraightStakes($scope.betSlip);
};
那麼你認爲我在這裏有什麼我的錯誤?
UPDATE
在移動應用中我做的完全一樣的功能,並有工作正常,看
HTML
<button ng-click="openRiskWinKeypad(null, 'RISKPARLAY')">
Risk: {{riskParlay}}
</button>
<strong>Total Stake: </strong>{{riskParlay | currency}}
<strong>To Win: </strong>{{winParlay | currency}}
控制器
applyParlayRisk = function(parlay, amount) {
$scope.riskParlay = amount;
$scope.winParlay = amount * (parlay.payoutProportion || 4.5);}
這裏有點不同NCE因爲我開的自定義鍵盤
$scope.openRiskWinKeypad = function(slip, type) {
$scope.keypad = {value: 0};
if (type === 'RISKSTRAIGHT' && slip.risk) {
$scope.keypad.value = slip.risk;
}
if (type === 'WINSTRAIGHT' && slip.win) {
$scope.keypad.value = slip.win;
}
$ionicPopup.show({
// here is where the keypad opens
}).then(function(amount) {
if (amount) {
switch (type) {
case 'RISKSTRAIGHT':
applyStraightRisk(slip, amount);
break;
case 'WINSTRAIGHT':
applyStraightWin(slip, amount);
break;
break;
case 'RISKPARLAY':
applyParlayRisk($scope.currentParlay, amount);
break;
}
}
sumStraightStakes($scope.betSlip);
});
};
編輯
,如果我做
<input type="text" ng-model="riskParlay"
ng-change="riskWinCalculations(null, 'RISKPARLAY')">
和
applyParlayRisk = function(parlay, riskParlay) {
$scope.riskParlay = riskParlay;
console.log($scope.riskParlay);
$scope.winParlay = riskParlay * (parlay.payoutProportion || 4.5);
}
和
case 'RISKPARLAY':
applyParlayRisk($scope.currentParlay, riskParlay);
console.log($scope.currentParlay.name);
break;
我得到的是
ReferenceError: riskParlay is not defined
這些代碼片段甚至沒有接近。首先,你傳遞'$ scope.riskParlay'作爲參數,在第二個傳遞一些其他值。 'applyParlayRisk($ scope.currentParlay,$ scope.riskParlay);','applyParlayRisk($ scope.currentParlay,amount);'第一個選項實際上並不合理,因爲您似乎在分配'$ scope.riskParlay'自身,因爲它是傳入的參數。 – Claies
@Claies這就是我想弄明白,這就是爲什麼問題是**問題邏輯**,因爲我的代碼有錯誤,否則我不會在這裏。 – NietzscheProgrammer
是在移動和桌面代碼庫之間共享的'applyParlayRisk'函數? – Claies