Wenn ich nach dem Laden der Seite zu list.html gehe, zeigt es mir die Liste nicht. Ich muss zuerst zu form.html und dann zurück zu list.html und dann gibt es mir die Liste. Als ich $ http-Funktionen im Controller hatte, funktionierte es wie ich wollte, aber jetzt, wo sie in Betrieb sind, funktionieren sie nicht wie zuvor.AngularJS ng-init funktioniert nicht
app.js
app.service("dataservice", function($http){
var list = [{}];
this.get = function(){
$http.get("harjoitus22/backend.php").success(function(response){
list = response;
});
};
this.save = function(newcontact){
$http({
method: 'post',
url: 'harjoitus22/backend.php',
data: newcontact,
header: 'Access-Control-Allow-Origin: *'
}).success(function(response){
list = response;
});
};
this.give = function(){
return list;
};
});
app.controller("mainController", function($scope, $location, dataservice){
$scope.save = function(){
dataservice.save($scope.newcontact);
$scope.newcontact = {};
$location.path("/list");
$scope.list = dataservice.give();
};
$scope.get = function(){
dataservice.get();
$scope.list = dataservice.give();
};
});
list.html
<tbody ng-init="get()">
<tr ng-repeat="object in list">
<td>{{object.nimi}}</td>
<td>{{object.email}}</td>
<td>{{object.ruoka}}</td>
<td>{{object.sauna}}</td>
</tr>
</tbody>
nicht "könnte", aber "sollte" hehe –
@AndrewDonovan hehe: fixed D. : p Danke für Heads Up Man .. –
haha keine probs! –