warning: I didn't run any of the below stuff through syntax checker or 
anything but it should be fairly close

1 - Angular resource already defines a GET for single objects and QUERY for 
arrays of json objects. 
So you should be able to simply "return $resource(path1);" in your MM 
service

2 - Add a controller for your app, and inject your service into the 
controller so we can call it
angular.module('whApp').controller('myCtrl', ['srvMM 
', function($scope, srvMM) { 
    $scope.testVar = "foobar"; 

    //if you have a single json object being received
    $scope.data = srvMM.get(function() { console.info('success'); }, 
function() { console.error('failed'); } );

    //if you have an array of json objects
    $scope.data = srvMM.query(function() { console.info('success'); }, 
function() { console.error('failed'); } );
} ] );

3 - In you html, bootstrap your angular app and output some stuff to make 
sure its working 
<div ng-app='whApp'>
<div ng-controller='myCtrl'> 
I should see foobar over here: {{  testVar }}
{{ data }}
</div>
</div>


Use debug console (network section) to make sure request looks as it is 
supposed to look (developer tools in chrome/firefox/...)
Let me know how that turns out, post any errors. 

/Brian


On Wednesday, May 13, 2015 at 12:07:09 PM UTC-4, o x wrote:
>
> this is my first time trying to get the json from local webService or from 
> a text file.
>
> i am using 
>      <!--AngularJS v1.3.15-->
>     <script src="Scripts/angular.min.js"></script>
>     <script src="Scripts/angular-route.min.js"></script>
>     <script src="Scripts/angular-resource.min.js"></script>
>     <script src="Scripts/angular-animate.min.js"></script>
>
> and the code 
>
> 'use strict';
>         var path1 = '
> http://localhost:53234/test/json/monthContainerJson.txt';
>                     //'test/json/monthContainerJson.txt'
>                     //wsWorkingHH.asmx/getMMSum
>
>         /* App Module */
>         var whApp = angular.module('whApp', ['whServices']);
>
>         /* Services */        
>         var whServices = angular.module('whServices', ['ngResource']);
>
>         whServices.factory('srvMM', ['$resource', function ($resource) {
>             return $resource(path1
>                                 , {}
>                                 , {
>                                     query: { method: 'GET', params: {}, 
> isArray: true }
>                                    }
>                                 );
>         }]);
>       
> var tryQ = whServices.query(function () {});
>         alert(tryQ[0]);
>
>
> what is wrong - the path? the syntax? 
> thanks
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to