1
Wie kann ich this
zu eckigen $http then
Callback übergeben, so dass ich Eigenschaften verwenden kann? Ist es möglich, das ohne $scope
zu tun? Hier ist mein Code:
angular.module('app').controller('CollectionCtrl',['$http','$scope', function ($http, $scope) {
this.formVisible = false;
this.showCollectionForm = function() {
this.formVisible = true;
};
this.hideCollectionForm = function() {
this.formVisible = false;
};
// New Collection Add
this.collection_name = '';
this.collection_text = '';
this.collection_nameError = false;
this.addCollection = function() {
if (this.collection_name === '') {
this.collection_nameError = true;
}
else {
this.collection_nameError = false;
var url = ROOT_URL + "api/post-image";
var data = {
'collection_name' : this.collection_name,
'collection_text' : this.collection_text
}
$http.post(url, data)
.then(
function(response){
this.hideCollectionForm();
$scope.fetchUserCollection();
},
function(response){
console.log('failure callback');
}
);
}
};
}]); Ich kann hideCollectionForm()
innerhalb then
Erfolg nicht aufrufen, weil es undefiniert ist.