0

I have an angular project. I am making an html/angular form - getting the data from a stored procedure via $http get in a service in angular. Now I want to databind some of the drop down lists in my filter that's in this html form. I have the data in a view which I made models for and added to the entity framework. How should I make calls to this breeze in angular? Code example please? in service or in controller?

------here's what i've tried--------------

what am I doing wrong here? (may be a few things...i'm new to angular. Then I just want to be able to somehow call this function populatestyleddl in my ng-model or something....

.factory('sellingService', ['$filter', '$http', function ($filter, $http) {


    function PopulateStyleDDL() {
        return breeze.EntityQuery.fromEntityNavigation('v_Style')
        .using(context.manager).execute();
    };
//check if above function is legal

    function SalesStatus(filter) {

        console.log(breeze);

        return $http({
            method: 'GET',
            url: '/Services/SalesStatus',
            params: { filter.itemStyle }
        }).then(function (result)
        { return result.data; })
    }
    return {
        SalesStatus: SalesStatus

    };





}]);

--------------------------------here's what i have now..... ok, here is what i've got now. this is happening in a js file where all my breeze calls are. Can you confirm if my syntax here is right and how my function syntaxically should look in my factory (and also how my syntax should look in my controller...)

function GetStyles() { return breeze.EntityQuery .from("v_Style") .using(manager) .execute(); }
Lisa Solomon
  • 136
  • 2
  • 15
  • what you have tried so far? – Pankaj Parkar Jan 27 '16 at 19:46
  • I believe you have the syntax for fromEntityNavigation wrong, for one thing. First parameter should be an entity (already retrieved from Breeze), and the second parameter should be a navigation property, or name of a navigation property. Can you explain what kind of data you are trying to retrieve and why a standard entityQuery won't work? – Beartums Jan 28 '16 at 14:00
  • can a factory have only one return? i already have this factory returning all of my data for my grid. now i want to add a filter to the grid and i want to databind the drop down list in the filter to my breeze. how would i do that? make new factory? add it to the existing one? I already added my breeze function to a whole seperate file - now i just have to call that somewhere!?! - in controller or factory? same factory or new one? – Lisa Solomon Jan 28 '16 at 15:24
  • Wow. That's a lot of questions. A factory should return an object, which can have multiple exposed functions and properties, if desired. I don't see any reason why not to add the PopulateDdlStyle funciton to the returned object -- I have no idea if it makes structural sense, but there is nothing wrong with it syntactically. Your questions are rather difficult to answer without a better understanding of your project. In short, put something in a factory if you want to reuse it or share it between controllers, or if it is consistent with what is already there. – Beartums Jan 28 '16 at 16:49
  • ok, here is what i've got now. this is happening in a js file where all my breeze calls are. Can you confirm if my syntax here is right and how my function syntaxically should look in my factory (and also how my syntax should look in my controller...) function GetStyles() { return breeze.EntityQuery .from("v_Style") .using(manager) .execute(); }; – Lisa Solomon Jan 29 '16 at 14:04
  • @LisaSolomon, ping me using @ and my username when replying to a comment (unless it's on my answer), otherwise I don't know you've made a comment – Beartums Jan 29 '16 at 19:48

1 Answers1

0

@LisaSolomon, regarding your syntax:

function GetStyles() { 
    return breeze.EntityQuery 
               .from("v_Style") 
               .using(manager) 
               .execute(); 
}

Looks good with the information I have. If it's not working I'd make sure:

  1. The controller has a properly-defined v_Style action, and
  2. The manager is defined and has the correct service name

So, assuming that is correct, you will need to add it to your returned object so that it is available in your controller:

return {
    SalesStatus: SalesStatus,
    GetStyles: GetStyles
};

Then to use it in your controller, you will need to reference the .then() of the promise

$scope.styles = '';
sellingService.GetStyles().then(function(data) {
    $scope.styles = data.results;
}).catch(function(err) {
   // error processing
});

Any error messages you're getting would be helpful. If there's any chance you could show controller and view code so we could build a fiddle, that would be great, too.

Beartums
  • 1,340
  • 1
  • 10
  • 15
  • @Beartrums - that almost worked! I got a drop down list populated like this now : [object] [object] (for the correct # of rows in result set) – Lisa Solomon Jan 31 '16 at 01:52
  • i have list [object Object] – Lisa Solomon Jan 31 '16 at 01:58
  • it was problem in html. i got it and it works good now! thanks! can you send what my html should look like in order that ngoptions will poulate list and ng-model will send back right value... – Lisa Solomon Jan 31 '16 at 02:02
  • Glad to help, but this should properly be another question. Please include the data you've got, the select options you'd like to see, the information you need returned, and the html you have now. Thanks – Beartums Jan 31 '16 at 04:00