Search code examples
jsonangularjsangular-ui-routerangular-resource

Angular Route vs $Resource


So I have a few REST URLs that I would like to load and bind to html when requested. When user searches for first name and if first name is found html gets populated from json. This works fine (Initial URL).

Initial URL

 var url = http://localhost:8080/userSearch/name/find?firstName='+enteredValue.firstName+'&lastName=&
 $http.get(url).success(function(data){
        $scope.dataItems= data; 

Now using ng-click on first name I want to request address and location based on these URLs

//URLs

 var url = http://localhost:8080/userSearch/addr/find?address=&address

 var url = http://localhost:8080/userSearch/loca/find?location=&location

So I started looking into UI-Router and $Resource. My first thought is to use $Resource but seems as if others have had problems with ports.

Could I use Router as well to solve this problem or should I stick with Resource?


Solution

  • ui-router and $resource are completely different things. ui-router is used to provide navigation between different states in your app while $resource is used to make calling server side APIs more convenient. If you need to retrieve data from a RESTful backend then $resource is the way to go. I'm not sure what you're referring to about the ports but I've built web applications that service millions of users daily on top of $resource and not had any port problems.