1

I have an AngularJS site based on BlurAdmin: https://github.com/akveo/blur-admin that shows rooms. The list of available rooms is gotten via REST in a controller and I am looking for a way to inject the rooms as submenu links dynamically.

My rooms.module.js file, which has an static sub menu link "room", looks like:

(function () {
  'use strict'; 
  angular.module('BlurAdmin.pages.rooms', [])
      .config(routeConfig);

  /** @ngInject */
  function routeConfig($stateProvider) {
    $stateProvider
        .state('rooms', {
            controller: 'roomsCtrl',
            url: '/rooms',
            templateUrl: 'app/pages/rooms/rooms.html',
            title: 'Rooms'
        });
    // Static sub menu link
    $stateProvider.state('rooms.details', {
            url: '/room/:roomLink/',
            controller: 'roomCtrl',
            title: 'Room',
            templateUrl: 'app/pages/rooms/room/room.html'
        });


  };

})();

My roomsCtrl.js file looks like:

(function () {
  'use strict';

  angular.module('BlurAdmin.pages.rooms').controller('roomsCtrl', roomsCtrl);

  /** @ngInject */
  function roomsCtrl($scope, $http, $timeout, $element, $state) { 

   // Here I'd like to process the REST response and create the submenu links.
   // Example of REST data
   var room = [{"name":"room 1", "id":"1"},{"name":"room 2", "id":"2"}]
   // Example of route
   var urlStr = "/rooms/room/1/"
  };



})();
John M.
  • 71
  • 8
  • you can create a menu directive, which pass the array of items to it. – Jesus Carrasco Jul 21 '17 at 23:52
  • What have you tried and what problems are you having with that approach? It would help to show us an example of the data that the REST api returns and the intended HTML template. – georgeawg Jul 22 '17 at 06:21
  • You can configure dynamic ui-router, check the below link, https://stackoverflow.com/questions/24727042/angularjs-ui-router-how-to-configure-dynamic-views – Eid Morsy Jul 22 '17 at 10:40
  • I have added an example of the data coming back - it's very basic. The template that would be used is empty right now so I really just need to figure out how to inject the links in the left menu. – John M. Jul 24 '17 at 16:46

0 Answers0