0

I have a code that uses to load data passing from the sever side into a jQGrid. I'm using an AngularJS factory method to initiate the call and return received json document. I'm getting Uncaught TypeError: Cannot read property 'loadDataToGrid' of undefined error in chrome console.

JQuery function to load data into jQGrid :-

$(function ($scope,$http,$rootScope,retriveDataFromServer) {
$("#list").jqGrid({
    url: retriveDataFromServer.loadDataToGrid($http),
    datatype: "json",
    mtype: "GET",
    colNames: ["Employee First Name", "Employee Last Name", "Contact No"],
    colModel: [
        { name: "fname", width: 55 },
        { name: "lname", width: 60 },
        { name: "contactNo", width: 55, align: "right" },
    ],
    pager: "#pager",
    rowNum: 10,
    autowidth: true,
    rowList: [10, 20, 30],
    sortname: "fname",
    sortorder: "desc",
    viewrecords: true,
    gridview: true,
    autoencode: true,
    caption: "Employee Data Grid"
 });
});

AngulaJS factory method :-

empApp.factory('retriveDataFromServer',function(){
return{
    loadDataToGrid: function($http){
        return $http({
            method : 'GET',
            url : 'http://localhost:8080/IdeaOne/viewall'
        }).then(function(response){
            return response;
        })
    }
 }
});

html :-

<div ng-app="empApp">
    <table id="list"><tr><td></td></tr></table>
    <div id="pager"></div>
</div>

when I directly load my data by specifying my url inside jQuery method it works fine.

Someone please point out where did I go wrong.

helloworld
  • 965
  • 5
  • 14
  • 34
  • You should read [__How do I “think in AngularJS” if I have a jQuery background?__](http://stackoverflow.com/questions/14994391/how-do-i-think-in-angularjs-if-i-have-a-jquery-background) Why are you not using [ngGrid](http://angular-ui.github.io/ng-grid/)? `jqGrid` is used with jQuery. And What is `$(function ($scope,$http,$rootScope,retriveDataFromServer) {`? – Satpal Apr 29 '14 at 06:34
  • @Satpal, I want to check a way to use jqGrid with AngularJS, and in here $(function ($scope,$http,$rootScope,retriveDataFromServer) I'm injecting those parameter into my jquery function to call my angularjs factory – helloworld Apr 29 '14 at 06:37

0 Answers0