我一直忙着嘗試AngularJS並遇到一個小問題。我會在下面顯示我的App.js和我的Index.html。AngularJS輸入推送到控制器
的Index.html
<ion-tab title="Home">
<ion-header-bar class="bar-dark">
<h1 class="title">Overzicht</h1>
</ion-header-bar>
<ion-content>
<ion-list>
<ion-item ng-repeat="info in inkomsten">
{{info.name }} <p class="float-left">{{info.value}}</p>
</ion-item>
</ion-list>
<ion-list>
<ion-item ng-repeat="info in uitgiften">
{{info.name }} <p class="float-left">{{info.value}}</p>
</ion-item>
</ion-list>
<ion-list>
<ion-item ng-repeat="info in tabel">
{{info.name }} <p class="float-left">{{info.value}}</p>
</ion-item>
</ion-list>
<form novalidate>
<input ng-model="name">
<input ng-model="value">
<input type="submit" ng-click="submitForm(name,value)" value="Click me!">
</form>
</ion-content>
</ion-tab>
<ion-tab title="Toevoegen">
</ion-tab>
<ion-tab title="Settings">
</ion-tab>
</ion-tabs>
</body>
app.js
angular.module('todo', ['ionic'])
.controller('TodoCtrl', function($scope) {
$scope.inkomsten= [
{ name: 'Salaris',value:'500' },
{ name: 'Toeslag',value:'200' },
{ name: 'Inkomsten',value:'211' },
{ name: 'Weekend', value:'22' }
];
$scope.uitgiften= [
{ name: 'eten',value:'120'},
{ name: 'kat',value:'230'},
{ name: 'schildpad', value: '300'},
{ name: 'huur', value: '200'}
];
}
});
我想對我的index.html 2個按鈕的人會給用戶一個選項,提交的新條目ng-repeat列表。這樣自然地,這些輸入將包含「inkomsten」或「uitgaven」組成。在選擇這些之後,用戶可以填寫新輸入的名稱,然後填入綁定的值。現在,我不知道如何將信息傳遞給app.js!
我希望你能理解我的問題。
在此先感謝
13:20 2015年7月12日
幫助之後,它現在看起來像這樣
app.js
.controller('TodoCtrl', function($scope) {
$scope.inkomsten= [
{ name: 'Salaris',value:'500' },
{ name: 'Toeslag',value:'200' },
{ name: 'Inkomsten',value:'211' },
{ name: 'Weekend', value:'22' }
];
$scope.uitgiften= [
{ name: 'eten',value:'120'},
{ name: 'kat',value:'230'},
{ name: 'schildpad', value: '300'},
{ name: 'huur', value: '200'}
];
$scope.addToNgRepeat = function(data) {
if(data === "uitgaven"){
$scope.uitgiften.push({name: $scope.name,value: $scope.value});
} else {
$scope.inkomsten.push({name: $scope.name,value: $scope.value});
}
}
});
的index.html
<form novalidate>
<input ng-model="name">
<input ng-model="value">
<input type="button" ng-click="addToNgRepeat("addToNgRepeat("uitgaven")")" value="uitgaven">
<input type="button" ng-click="addToNgRepeat("addToNgRepeat("inkomsten")")" value="inkomsten">
</form>
現在還不行,我現在做錯了什麼? :(
但是如何確保它被添加到適當的值? 「inkomsten」或「uitgiften」..我會在submitForm()中添加$ scope.name和$ scope.value嗎? –
您可以將參數傳遞給您的submitForm()像我的例子 – GuoX
我將修改我的問題,以顯示更新的版本 –