如何在控制器Angular JS中启动路由?

时间:2015-04-08 11:37:58

标签: angularjs

我需要在控制器ChatController中调用代码,而不是在全局应用程序中调用:

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

我怎么做?

我试过(模板没有加载div):

Angular JS:

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

HTML:

<div ng-include src="{{template}}"></div>

1 个答案:

答案 0 :(得分:1)

我同意@ Nano,所有使用角度的提供商都注入并在其中使用 .config ,您无法在控制器中使用它。