简体   繁体   中英

Calling a function using Restangular in Angularjs

Here is the test function I have defined in my view's controller

scope.getItem = function () {
    var promise = Restangular.one('item').load();
    promise.then(function (result) {
        return 'foo';
    });
    return '';
};

In my view, I am trying to call this function, but I get an error saying that Restangular.one().load is not a function. What am I doing wrong here ?

Thanks

使用get代替load ,Restangular中没有load函数:

var promise = Restangular.one('item').get();

I think you need to call

scope.getItem = function () {
    var promise = Restangular.one('item').get();
    promise.then(function (result) {
        return 'foo';
    });
    return '';
};

Also make sure that you inject the Restangular Service into your controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM