Quantcast
Channel: BTSoru.com - Bilisim ve Yazilim Teknolojileri Soru/Cevap Platformu - latest questions
Viewing all articles
Browse latest Browse all 4270

Angular JS'de resource kaydederken promise dönmemesi

$
0
0

Selam arkadaşlar,

AngularJS'de Events uygulaması ile uğraşıyorum.Service javascriptinde Ngresource ile yeni bir event'i kaydetmeden önce var olan event idleri resource.query() ile kontrol edip en yüksek id'yi bir arttırarak yeni event id'ye atayıp controllere döndürüyorum.Event id başarılı bir şekilde set ediliyor ancak controllerdan aşağıdaki gibi bir hata alıyorum:

angular.js:12221 TypeError: Cannot read property '$promise' of undefined
at Scope.EditEventController.$scope.saveEvent (EditEventController.js:27)
at fn (eval at compile (angular.js:13036), <anonymous>:4:431)
at callback (angular.js:23090)
at Scope.$eval (angular.js:15719)
at Scope.$apply (angular.js:15818)
at HTMLButtonElement.<anonymous> (angular.js:23095)
at HTMLButtonElement.dispatch (jquery.min.js:3)
at HTMLButtonElement.i (jquery.min.js:3)

EventData.js

eventsApp.factory('eventData', ['$q', '$resource', function EventData($q, $resource) {
var resource = $resource('/app/data/event/:id', {
    id: '@id'
}, {
    "getAll": {
        method: "GET",
        isArray: true,
        params: {
            something: "foo"
        }
    }
});

return {
    getEvent: function(eventId) {
        return resource.get({
            id: eventId
        });
    },
    save: function save(event) {

        var tempid = 0;

        resource.query(function(events) {
            angular.forEach(events, function(temp_event) {
                if (temp_event.id> tempid) {
                    tempid = temp_event.id;
                    console.log("----" + tempid + "----");
                }
            });

        }).$promise.then(function(response) {
            console.log('success1', response);
            event.id = tempid + 1;
            console.log("New event id " + event.id);
            return resource.save(event).$promise;

        }).catch(function(response) {
            console.log('failure1', response)
        });

    },
    getAllEvents: function() {
        return resource.query();
    }
  };
 }]);

EditEventController.js

'use strict';

eventsApp.controller('EditEventController',
function EditEventController($scope, eventData, $location) {

    $scope.event = {};

    $scope.saveEvent = function(event, newEventForm) {
        if (newEventForm.$valid) {

            eventData.save(event).$promise.then(function(response) {
                console.log('success3', response);
                $location.url('/events');
            }).catch(function(response) {
                console.log('failure3', response)
            });
        }
    };

    $scope.cancelEvent = function() {
        window.location = '/EventDetails.html';
    }

}

);

Yardımlarınızı bekliyorum.Çok teşekkürler.


Viewing all articles
Browse latest Browse all 4270

Trending Articles


Celcelutiye vefki (Celcelutiye Kübra Daveti)


BBasTTuuHHaaNN


Korunma zirhi


Sıkıntıyı gideren Ismi Celil duası


Cinleri Kovma Babı


Cin çağırma


Hizbul Vikâye (Koruyucu Dua) Ruhsal Yükselme ve Korunmak


SCCM 2012 Client Installation issue


Karanfil ve Surei İhlas ile CELB


Karia Suresi ile Celb


Sübhanallahi milel mizan


Taslit ve Darp


Ve huvel kaviyyul azîz


gaipten altın ve para getirmek için


9999 Adet innâ fetahnâ leke fethan mubinâ


Hadid suresinin vefki


Ya Cebbar;Yâ Cebbar c.c:Dilediğini zorla yaptırmaya


Bu dua ismi azam midir?


Süfli Hadim-Cin Daveti


Şura Suresi 19. Ayet Mucizesi