我想在单击按钮后将输入值设置为null。单击按钮后,spremi()会执行它的操作,但我希望将podaci.tezina和podaci.mamac的值设置为起始值,以便用户输入新值。
.controller('SpremiCtrl', function($scope, $localStorage, $ionicPopup, $location, $window) {
$scope.ribe = ["Saran", "Stuka", "Som"];
var ribice = [];
$scope.spremi = function(t_tezina, m_mamac){
console.log(t_tezina);
console.log(m_mamac);
var podaci = {Tezina: t_tezina, Mamac: m_mamac};
console.log(podaci);
ribice.push(podaci);
$localStorage.fish = ribice;
console.log(ribice);
var confirmPopup = $ionicPopup.alert({
title: 'Spremljeno'
});
};
html
<ion-view view-title="Browse">
<ion-content>
<select id="vrstaribe" ng-model="selekt" ng-options="r as r for r in ribe" selected>
<option value="">Vrsta ribe</option>
</select>
<label class="item item-input">
<input id="tezina" type="number" placeholder="Tezina" ng-model="podaci.tezina">
</label>
<label class="item item-input">
<input id="mamac" type="text" placeholder="Mamac" ng-model="podaci.mamac">
</label>
<button class="button button-positive" ng-click="spremi(podaci.tezina, podaci.mamac)">Spremi</button>
<button class="button button-positive" ng-click="dohvati()">Prikaži</button>
<button class="button button-positive" ng-click="isprazni()">Isprazni</button>
</ion-content>
</ion-view>
答案 0 :(得分:0)
您应该在所有其他逻辑之后重置方法末尾的值,以便下次调用时它是新鲜的。
$scope.spremi = function(t_tezina, m_mamac){
console.log(t_tezina);
console.log(m_mamac);
var podaci = {Tezina: t_tezina, Mamac: m_mamac};
console.log(podaci);
ribice.push(podaci);
$localStorage.fish = ribice;
console.log(ribice);
var confirmPopup = $ionicPopup.alert({
title: 'Spremljeno'
});
// reset your variables here.
podaci.Tezina = '';
podaci.Mamac = '';
};
还应该注意,您应该使用$log.debug()
(或朋友)而不是console.log()
,因为您可以在构建版本时通知$logProvider
禁用调试输出而不是调试。这可以让生活更轻松。