0
我有這個問題,我無法解決它。角度 - ng模型輸入在控制器中爲空
當我得到我的控制器中的輸入字段的值都是空的,爲什麼?
HTML
<input type="number" ng-model="formSearchAtt.numPartecipanti" id="partecipanti" value="0" class="price-input">
<button class="btn btn-default btn-green btn-3-column sidebar-filtri-button" ng-click="search()">Cerca</button>
控制器
tantoSvagoApp.controller("ricercaAttivita", function ($scope, $http, serviceRegioni, serviceRicercaAttivita, srvShareData) {
$scope.search = function() {
$scope.formSearchAtt = {'numPartecipanti' : ""};
var numPartecipanti= $scope.formSearchAtt.numPartecipanti;
console.log("numPartecipanti " + numPartecipanti);
}
});
所以,你初始化值(這應該是一個數字,BTW)爲空字符串,然後緊接着,你打印這個值,它是一個空字符串。什麼是令人驚訝的呢?如果您希望默認值爲0,請將其初始化爲0.其值在用戶更改時會更改(即在用戶與UI交互時變量初始化後很長時間) –