my service code belowed :-
data.service('smartlearnerservice', function ($http) { //get single records this.get = function (id) { return $http.get("/api/category/"); } }); here controller code app.js:-
$scope.questionlist = smartlearnerservice.get(); $scope.questionlist.then(function (pl) { var res = pl.data; $scope.que = res.questionlabel; }, function (errorpl) { console.log('failure loading employee', errorpl); }); console.log($scope.questionlist); here controller code web api controller :-
public class categorycontroller : apicontroller { commondb db = new commondb(); public jsonresult get() { var result = db.getquestionbyid().tolist(); string message = "no data found"; if (result.count() != 0) { return new system.web.mvc.jsonresult() { data = result, jsonrequestbehavior = system.web.mvc.jsonrequestbehavior.allowget }; } else { return new system.web.mvc.jsonresult() { data = message, jsonrequestbehavior = system.web.mvc.jsonrequestbehavior.allowget }; } } } } and here div tag want bind questions json result using ng-repeat directive.
<div class="question" align="center">{{questions.questionlabel}}</div> i facing problem while binding json array in controller's $scope.questionlist , getting json result web api controller.
ok, if had guess (and that's i'm doing), want in controller...
smartlearnerservice.get().success(function(questions) { $scope.questionlist = questions; }); or, if you're not fan of add-on success / error callbacks
smartlearnerservice.get().then(function(response) { $scope.questionlist = response.data; }); and in template
<div ng-repeat="question in questionlist"> <div class="question" align="center">{{question.questionlabel}}</div> <!-- , on --> </div> this totally assuming c# controller returns json looks like...
[{ "questionid": "1", "questionlabel": "why mirrors curved (convex) ?", "image": "zibra-crossing.jpg", "correct": "two", "explaination": "question 1 explaination goes here" }, { ... }]
Comments
Post a Comment