0

I need that code will be called in controller ChatController, not in global application:

.config(function($routeProvider){
            $routeProvider.when("/chat/dialog/:id",
                {
                    templateUrl: "/template/chat/active_dialog.html",
                    controller: "ChatController"
                }
            );
        })

How I can do it?

I tried (template is not loaded in div):

Angular JS:

$scope.selectDialog = function (id, event){
   $scope.template = '/template/chat/active_dialog.html';
});

HTML:

<div ng-include src="{{template}}"></div>
Sahe
  • 163
  • 4
  • 14
  • Seems similar to this http://stackoverflow.com/questions/16384134/how-to-call-a-function-in-angularjs-when-route-matches .Is that what you are looking for? – kubuntu Apr 08 '15 at 11:46
  • could you be a little more specific? what do you mean with "not in global application"? Do you want to define the Route in the controller (not possible)? – Nano Apr 08 '15 at 11:46
  • Yes, I want to define route in Controller, is it not possible? How I can load template then? – Sahe Apr 08 '15 at 11:48
  • 1
    the `$routeProvider` is just accesable in the config phase of the application, that means you cant use the `$routeProvider` in controllers. The template is loadet automaticly from the url you set in `templateUrl` – Nano Apr 08 '15 at 11:49
  • you could create a separate module for this? I imagine you would need to create a third module for anything shared between modules. – trees_are_great Apr 08 '15 at 12:02

1 Answers1

1

I agree with @Nano,all the providers that are used angular are injected and used in .config,you directly cannot use it in your controller.

Ritt
  • 3,181
  • 3
  • 22
  • 51