0
上週我做了一個函數,它從一對按鈕(一個是true,一個是false)中取出一個true/false值並將其放入$ scope變量。
它工作完美。
$scope.trueOrFalse = function(truefalse) {
if (truefalse == false){
$scope.value = false;
document.getElementById("makeFalse").className = "button active";
document.getElementById("makeTrue").className = "button";
console.log($scope.isBusiness);
} else if(truefalse == true){
$scope.value = true;
document.getElementById("makeTrue").className = "button active";
document.getElementById("makeFalse").className = "button";
console.log($scope.value);
}
}
但現在,我已經基本上同樣的事情在另一個網頁,其唯一的工作一次,在第一次點擊,其中,如果選擇的值是假的,我得到一個console.log它是錯誤的,那麼如果再次點擊,就不會發生任何改變。
但如果選擇的值是true,那麼下一次點擊嘗試,我開始得到:
類型錯誤:FN是不是一個函數
at $parseFunctionCall (ionic.bundle.js:21045);
at ionic.bundle.js:53458;
at Scope.$get.Scope.$eval (ionic.bundle.js:23100);
at Scope.$get.Scope.$apply (ionic.bundle.js:23199);
at HTMLAnchorElement.<anonymous> (ionic.bundle.js:53457);
at HTMLAnchorElement.eventHandler (ionic.bundle.js:11713);
at triggerMouseEvent (ionic.bundle.js:2863);
at tapClick (ionic.bundle.js:2852);
at HTMLDocument.tapMouseUp (ionic.bundle.js:2925);
這是怎麼回事?
這裏的HTML
<ion-view view-title="Biz Post/Uploading">
<ion-content>
<!-- Begin Second Set of Tabs -->
<div class="button-bar">
<a class="button" id="item" data-ng-click="isDeal(false)">Item</a>
<a class="button" id="deal" data-ng-click="isDeal(true)">Deal</a>
</div>
<!-- End Second Set of Tabs -->
<!-- Section -->
<div class="list-inset">
<center><img src="http://placehold.it/350x150"></center>
</div>
<div class="list">
<div class="item item-divider">
Add thing
</div>
<label class="item item-input item-stacked-label">
<span class="input-label">thing</span>
<input type="text" placeholder="add location" ng-model="thing.thing2">
</label>
<label class="item item-input item-stacked-label">
<span class="input-label">thing</span>
<input type="text" placeholder="add price" ng-model="thing.thing3">
</label>
<label class="item item-input item-stacked-label">
<span class="input-label">thing</span>
<input type="text" placeholder="add item description" ng-model="item.thing">
</label>
<label class="item item-input">
<span class="input-label">Date</span>
<input type="date">
</label>
<label class="item item-input item-stacked-label">
<span class="input-label">thing</span>
<input type="text" placeholder="set limit" ng-model="thing.thing4">
</label>
<button class="button button-full button-balanced" data-ng-click="pushData()">
push data
</button>
</div>
</ion-content>
</ion-view>
請還顯示代碼HTML與兩個按鈕 – manzapanza
是的控制器正在加載新頁面?也許範圍不會在第一次點擊之後更新。 – isherwood
是的,控制器被加載,它打印出第一個console.log的真或假值 – Femtosecond