0

I have a small app that shows a calendar with some events.

When I click on one of the events I would like to show details of the selection below the calendar.

The events' urls are generated within a loop like this :

'url': '#/concerts/' + data[idx].id

and my config is the following:

var app = angular.module('EventsApp', ['ngRoute']);

app.config(['$routeProvider', '$locationProvider',
    function ($routeProvider, $locationProvider) {
        $routeProvider.
            when('/concerts/:eventId', {
                templateUrl: '/Views/Home/ng-view/details.html',
                controller: 'EventCtrl'
            }).
        otherwise({
            redirectTo: '/'
        });
    }]);

My Index.cshtml:

<div id="bodyApp" ng-app="EventsApp">
    <div class="mainBody" ng-controller="EventCtrl as event" ng-init="event.getAllConcerts()">
        <div class="search">
            <input type="search" />
        </div>
        <div class="calendar">
             <div id="calendar">

            </div>
       </div>
       <div class="crudSection" ng-view>

    </div>
</div>

At the moment I am just trying to get the details.html to be shown, but It doesn't redirect. The url is updated with the proper one but my view is not refreshed.

Also, How should the routeProvider config to do a webapi call without exposing the '/api/{controller}/{id}' info?

Edit.: I tried with the standard MVC route '/Home/{action} and a partialview and it works, but not a '/Home/{action}/{id}', so I think I'm missing something about how to combine both routings.

blfuentes
  • 2,731
  • 5
  • 44
  • 72

1 Answers1

0

I found the solution in the following link:

AngularJS - How to use $routeParams in generating the templateUrl?

app.config(['$routeProvider', '$locationProvider',
    function ($routeProvider, $locationProvider) {
        $routeProvider.
            when('/concerts/:eventId', {
                templateUrl: function (params) { return '/Home/Details/' + params.eventId; },
                controller: 'EventCtrl'
            }).
        otherwise({
            redirectTo: '/'
        });
    }]);
Community
  • 1
  • 1
blfuentes
  • 2,731
  • 5
  • 44
  • 72