angularjs - Using Angular $resource, Fetch data on button click not working -


i using angularjs ngresource fetch list of data database on button click. when click button nothing happens. doing wrong.

app.js

'use strict'; var app = angular.module('app',['ngresource']); 

graph_service.js

'use strict'; app.factory('graph', ['$resource', function ($resource) {     return $resource(             'http://localhost:8080/spsystem/stats'          ); }]); 

graph_controller.js

'use strict'; app.controller('graphcontroller', ['$scope', 'graph', function($scope, graph) {           var self = this;           self.graph= new graph();            self.graphs=[];            self.fetchallstats = function(){               self.graphs = graph.query();            }       }]); 

minimal html

<body ng-app="app" class="ng-cloak"> <div class="generic-container" ng-controller="graphcontroller ctrl">   <div class="panel panel-default">     <div>             <input type="button" ng-click="fetchallstats()" value="fetch" class="btn btn-success">     </div>                 <div class="panel-heading"><span class="lead">list</span></div>     <div class="tablecontainer">       <table class="table table-hover">        <thead>         <tr>          <th>x</th>          <th>y</th>          <th width="20%"></th>           </tr>           </thead>           <tbody>           <tr ng-repeat="g in ctrl.graphs">       <td>{{g.x}}</td>       <td>{{g.y}}</td>             </tr>     </tbody>     </table>                   </div>      </div>         </div>  </div>  </body> 

you don't have method named query in factory,

change factory this,

app.factory('graph', ['$resource', function ($resource) {   {     // resource object      var resource = $resource('http://localhost:8080/spsystem/stats');             /* custom function retrieve issue list*/     resource.query= function () {         return this.query()           };            return resource;   }) 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -