A
A
Alexander2016-05-13 11:33:13
JavaScript
Alexander, 2016-05-13 11:33:13

How to open different templates depending on angular setting?

There is a route

.state('app.catID', {
    url: '/catid/:catID',
    views: {
        'menuContent': {
          templateUrl: 'templates/category.html',
          controller: 'catCtrl'
          },
        'filterView': {
          templateUrl: 'templates/filter.html',
          controller: 'filCtrl'
        },
          'sideView': {
           templateUrl: 'templates/category/category_dynamic.html',
           controller: 'categoryMenuCtrl'
        }
      }
  })

How to make it so that when the parameter catid = 123 - then
'filterView': {
templateUrl: 'templates/filter123.html',
controller: 'filCtrl'
},
and when
456
'filterView': {
templateUrl: 'templates/filter456.html ',
controller: 'filCtrl'
},
,
and in all other cases just filter.html ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Osher, 2016-05-13
@ghost1k

angular-ui.github.io/ui-router/site/#/api/ui.route...

filterView: {
    templateUrl: function (params) {
      return 'templates/filter' + params.catID + '.html';
   }
}

B
bromzh, 2016-05-13
@bromzh

https://docs.angularjs.org/api/ng/directive/ngInclude
But this smacks of g-nocode. Make a directive, pass catid to it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question