H
H
HAbRAhabp2016-03-08 17:33:25
Angular
HAbRAhabp, 2016-03-08 17:33:25

Question about application architecture and ngRoute?

Hello. I will try to briefly describe the essence of my problem. Here is the code:

<body ng-app="Arenda" ng-controller="RootController">
<nav></nav>
<div ng-if="bgPageHeaderEnabled" ng-include="&quot;ng_templates/bg-pageheader.html&quot;"></div>
<div class="container" ng-view>
</body>

JS: (sorry for the coffeescript)
app = angular.module "Arenda", ['ngMaterial', 'ngRoute'] # module init

`
app.config ($routeProvider) ->
  $routeProvider
  .when '/', 
    controller: 'RoomController'
    templateUrl: 'ng_templates/rooms.html'
  
  .when '/room/:id', 
    controller: 'PhotoController',
    templateUrl: 'views/photo.html'
  
  .otherwise 
    redirectTo: '/'
  return

app.controller "RootController", ['$scope', '$http', ($scope, $http) ->
  $scope.bgPageHeaderEnabled = true;
]

I cut out the rest of the controllers, because. they are not needed. How to change the bgPageHeaderEnabled parameter in the RootController to false when routing to another page, for example? Or what is the best way to do it? I hope I explained correctly

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bulat Kurbangaliev, 2016-03-08
@HAbRAhabp

I don’t know about the default router, but ui-router (defacto in angular) has such a feature as resolve. https://github.com/angular-ui/ui-router/wiki#resolve
It allows you to pass the necessary parameters to the state through dependency injection.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question