How should i manipulate angularjs resource object for use in the view

Suziemac Tani

Learning javascript and chosen angularjs as a frame work to work with. In my project i use django-tastypie

{

    "meta": { … },
    "objects": [ … ]

}

to create api which i use in angularjs to obtain a resource object which works perfectly,

app.factory('category',['$resource',function($resource){
  return $resource('/api/v1/menu/?format=json',{},{'query':{method:'GET',isArray: false}})
}]);

my problem comes up after i traverse the resource object in my controller,

app.controller('mainCtrl',['category','$scope',function(category,$scope) {
 var data = category.query();
 $scope.categories = data.$promise.then(function(result){
     return result.objects;
  });
}]);

so as to make use of the data in my view,

<li  ng-repeat="category in categories"style="color:black;">
            [[category]]
</li>

But the view never renders the data, category doesn't result to anything

I have surely looked around,done some googling but i feel i would understand if got help with my own problem. Angularjs is complicated and the tutorials out there are not making it any easy.

I do appreciate a good explanation with some examples and links if available.

Foo L

Since the request is async, you need to assign the results of the call after the call has successfully returned, so:

data.$promise.then(function(result){
  $scope.categories = result.objects;
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

angularjs: how to add caching to resource object?

How to use AngularJS $resource custom actions?

ExtJS 6: Should I use the config object?

How can i manipulate the select options by angularjs

Should I use Material for Angular or Material for AngularJS?

Terraform - should I use user_data or provisioner to bootstrap a resource?

Should I use factory to update object?

what type of azure resource should i use for hosting many database

How should I correctly use setState for the following object

how to use JSONP in AngularJS resource

Should I use `.blank?` in a view of performance?

Should I always initialize view model object?

How to get keys of Resource object in AngularJS?

Should I use associative arrays in AngularJS?

How do I make an AngularJS directive manipulate all elements associated with it?

How to manipulate LIst<Object>

How to manipulate an XDocument object

AngularJS 1.x How do I use resource to fetch an array of results?

Should I use vue-resource on Vuex actions

Should i use Laravel Passport or JWT resource?

How do I manipulate with Google Forms on Form View, client side

How should I use route and view in laravel

How should I use WebElements and Actions through page object model?

How do I make this view With bootstrap grid? or should I use list-group?

How should I update a resource that is fully depend on other resource

What Box like view should I use?

Should I use RTK Query per base URL or Resource?

Should I use PATCH or POST to create and update a resource at the same time?

How do i manipulate data or values of collection view items?

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    pump.io port in URL

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  14. 14

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  15. 15

    How to use merge windows unallocated space into Ubuntu using GParted?

  16. 16

    flutter: dropdown item programmatically unselect problem

  17. 17

    Pandas - check if dataframe has negative value in any column

  18. 18

    Nuget add packages gives access denied errors

  19. 19

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  20. 20

    Generate random UUIDv4 with Elm

  21. 21

    Client secret not provided in request error with Keycloak

HotTag

Archive