Restangular get url parameters

336 views
Skip to first unread message

Hilaal Agil

unread,
Aug 27, 2013, 6:42:32 AM8/27/13
to ang...@googlegroups.com
hello,

i am quite new to angularJs.

i am trying to retrieve an object based on the url parameter.

for example i have the following code:

var tripApp = angular.module('tripApp', ['ui.state', 'ui.bootstrap', 'restangular', 'tripApp.directives', 'restaurantServices'])
    tripApp.config(function($stateProvider, $urlRouterProvider, RestangularProvider){

      RestangularProvider.setBaseUrl('json');
      RestangularProvider.setRequestSuffix('.json');

      $urlRouterProvider.otherwise("/hotels")
      
      $stateProvider
        .state('hotels', {
            url: "/hotels/:id",
            templateUrl: "templates/hotels.html",
            controller: "HotelDetailController"
        })

and my controller as:

tripApp.controller('HotelDetailController', function($scope, $timeout, Restangular) {
    
});

how would i be able to retrieve a record based on the field 'url' if my json file was:

{
  "hotels":
  [
    {
            "url":"bandos-island-resort",
    "name": "Bandos Island",
            "city": "Male",
            "country": "Maldives",
    "price": 199,
    "offer": 50,
    "standard": [1, 2, 3, 4],
    "roomsleft": 4,
            "facilities": [
                {
                    "wifi": true,
                    "breakfast": false,
                    "spa": false,
                    "beachAccess": false,
                    "pool": false,
                    "airportShuttle": false,
                    "restaurant": false,
                    "bar": false,
                    "coffeeShop": false,
                    "noSmoking": false,
                    "petFriendly": false,
                    "jacuzzi": false,
                    "laundry": true,
                    "miniBar": false,
                    "parking": false,
                    "roomService": false,
                    "sauna": false,
                    "scubaDiving": false,
                    "snorkeling": false,
                    "waterSkiing": false,
                    "windSurfing": false,
                    "tennis": false,
                    "golf": false,
                    "weddingPlan": false
                }
            ] 
    },
    {
            "url":"bandos-island-resort",
    "name": "Club Faru",
    "price": 299,
    "offer": 0,
    "standard": [1, 2, 3],
    "roomsleft": 4,
            "facilities": [
                {
                    "wifi": true,
                    "breakfast": false,
                    "spa": false,
                    "beachAccess": false,
                    "pool": false,
                    "airportShuttle": false,
                    "restaurant": false,
                    "bar": false,
                    "coffeeShop": false,
                    "noSmoking": false,
                    "petFriendly": false,
                    "jacuzzi": false,
                    "laundry": false,
                    "miniBar": false,
                    "parking": false,
                    "roomService": false,
                    "sauna": false,
                    "scubaDiving": false,
                    "snorkeling": false,
                    "waterSkiing": false,
                    "windSurfing": false,
                    "tennis": false,
                    "golf": false,
                    "weddingPlan": false
                }
            ]
    }
   ]
}

i am able to retrieve the whole file and repeat the data, but i would like to filter a record based on the url field and use it in my view. any help would be appreciated. thanks
Reply all
Reply to author
Forward
0 new messages