pixis
asked on
AngularJS - Can't display my query object in angularjs using ng-repeat querying with odata
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.Compan yName}}. 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('compa nyUpdateIn dexCtrl', ['$scope', 'companies', function ($scope, companies ) {
companies.getById(2932).su ccess(func tion (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="compan iesIndexCt rl">
<div><label style="padding-right:25px" >Select a Company</label>
<select ng-model="companies.Compan yName">
<option ng-repeat="x in companies">{{x.CompanyName }}</option >
</select>
My api function:
api.prototype.getAll = function (data) {
return dataService.get(this.baseU rl + odata.queryString(data));
};
Using api function:
'use strict';
define(['app', 'js/services/api'], function (app) {
var register = app.register || app;
register.factory('companie s', ['api', function (api) {
var Companies = new api('Companies');
return Companies;
}])
});
This is my controller:
'use strict';
define(['app', 'js/services/companies'], function (app) {
var register = app.register || app;
register.controller('compa
companies.getById(2932).su
$scope.company = data;
}).error(function (data) {
//handle error
});
$scope.companies = companies;
companies.getAll().success
$scope.all = data;
}).error(function (data) {
});
}]);
});
This is my html:
<div data-ng-controller="compan
<div><label style="padding-right:25px"
<select ng-model="companies.Compan
<option ng-repeat="x in companies">{{x.CompanyName
</select>
My api function:
api.prototype.getAll = function (data) {
return dataService.get(this.baseU
};
Using api function:
'use strict';
define(['app', 'js/services/api'], function (app) {
var register = app.register || app;
register.factory('companie
var Companies = new api('Companies');
return Companies;
}])
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Instead of this try using
<select name="selectedcompany" ng-model="companies">