AngularJS - is the function returning usable JSON formatted data, and how to wire it to <select>

//this function is supposed to return JSON data...

$scope.returnServiceType = function (stEnum) {
        var deferred = $q.defer();
        $http.get('/Ticket/ReturnServiceTypes', {
            params: {
                stEnum: stEnum
            }
        }).success(deferred.resolve).error(deferred.reject);

        return deferred.promise;
    }

 $scope.mTicketType = $scope.returnServiceType("calltype");

Open in new window





//This code is where the data above is bound to the <select> tag (combobox):

 <div class="ctrlRow">
        <label class="lbl">@Resources.ResStrings.TYPE:</label>        
         <select class="callSetting" ng-model="mTicketType"  ng-options="ticket.name for ticket in returnServiceType">
        </select>
    </div>

Open in new window



I've been stepping through the C# code behind, and as far as I can tell, the data is being converted over to JSON:

 public ActionResult ReturnServiceTypes(ServiceTypesEnum stEnum)
        {
            List<ServiceType> sTypes = ticketService.ReturnServiceTypes(stEnum);

            return Json(sTypes, JsonRequestBehavior.AllowGet); // set breakpoint here...
        }

Open in new window


Pasted in from the debugger Immediate Window at runtime:

((System.Web.Mvc.ContentResult)Json(sTypes, JsonRequestBehavior.AllowGet)).Content
"[{\"name\":\"Electrical\"},{\"name\":\"Installation\"},{\"name\":\"Jam\"},{\"name\":\"PM\"},{\"name\":\"CopyQuality\"},{\"name\":\"Receive-Send\"},{\"name\":\"Shop\"},{\"name\":\"Delivery\"},{\"name\":\"CourtesyCall\"},{\"name\":\"PhoneFix\"},{\"name\":\"eInfo\"},{\"name\":\"Not Working\"}]"

Open in new window







1)  How can I tell if the function is returning JSON data that the angular syntax can consume?
2)  Is the HTML properly wired-up to the Javascript via Angular commands?
3)  How can I debug this?  The JSON data seems to fall into a black hole.  I can't figure-out where to stop or what to look at in the Chrome F12 Developer Tools to verify that the function is returning JSON data...all I see is this:


get to JSON data?
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
How can I tell if the function is returning JSON data that the angular syntax can consume?
If that's what you got from the Immediate Window, then it should be fine for Angular.

Is the HTML properly wired-up to the Javascript via Angular commands?
Hmmm. I don't know about this line:

<select class="callSetting" ng-model="mTicketType"  ng-options="ticket.name for ticket in returnServiceType">

Open in new window


Shouldn't that ng-options be:

ng-options="ticket.name for ticket in mTicketType"

How can I debug this? ...
Chrome or Firefox would be the preferred choices. You need to be focused on the service file itself. That is where you would want to put your breakpoint(s). That is, whichever file contains the "returnServiceType" code.
0
leakim971PluritechnicianCommented:
replace
$scope.mTicketType = $scope.returnServiceType("calltype");

Open in new window

by :
$scope.returnServiceType("calltype").then(function(data) {
          $scope.mTicketType = data;
});

Open in new window


more info about promise here : https://docs.angularjs.org/api/ng/service/$q
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tom KnowltonWeb developerAuthor Commented:
thx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.