?
Solved

AngularJS - Can't display my query object in angularjs using ng-repeat querying with odata

Posted on 2014-12-01
2
Medium Priority
?
287 Views
Last Modified: 2014-12-03
I'm trying to figure out how to display a list of companies from an Entity Framework table. I'm using odata, and it currently works to getById and pass it an id manually. However, when I use my `getAll()` method to to grab all of the companies I can't get it to work. In my html I use something like this in a select dropdown menu: ng-repeat="company in companies"{{company.CompanyName}}. When I do this all I get are like two blank selections with no names no nothing. Can someone give me some advice?

This is my controller:

    'use strict';
   
    define(['app', 'js/services/companies'], function (app) {
   
        var register = app.register || app;
   
        register.controller('companyUpdateIndexCtrl', ['$scope', 'companies', function ($scope, companies ) {
               
                companies.getById(2932).success(function (data) {
                $scope.company = data;
            }).error(function (data) {
                //handle error
            });
                $scope.companies = companies;
                companies.getAll().success(function (data) {
                    $scope.all = data;
                }).error(function (data) {
   
                });
        }]);
   
    });

This is my html:

    <div data-ng-controller="companiesIndexCtrl">
    <div><label style="padding-right:25px">Select a Company</label>
        <select ng-model="companies.CompanyName">
            <option ng-repeat="x in companies">{{x.CompanyName}}</option>
        </select>


My api function:

        api.prototype.getAll = function (data) {
            return dataService.get(this.baseUrl + odata.queryString(data));
        };


Using api function:

    'use strict';
   
    define(['app', 'js/services/api'], function (app) {
   
        var register = app.register || app;
   
        register.factory('companies',  ['api', function (api) {
   
            var Companies = new api('Companies');
            return Companies;
        }])
   
    });
0
Comment
Question by:pixis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
Jitendra Patil earned 1000 total points
ID: 40477877
can you try the below code
<select name="selectedcompany" ng-model="companies.CompanyName">
         <option ng:repeat="x in companies" value="{{x.CompanyName}}">{{x.CompanyName}}</option>
     </select>  

instead of this
   <select ng-model="companies.CompanyName">
            <option ng-repeat="x in companies">{{x.CompanyName}}</option>
        </select>

for your reference you can also try the below link
HTML SELECT element with angular data-binding.

hope this helps.
0
 
LVL 17

Expert Comment

by:Shinesh Premrajan
ID: 40478184
<select name="selectedcompany" ng-model="companies.CompanyName">

Instead of this try using

<select name="selectedcompany" ng-model="companies">
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question