我可以在角度js asp.net mvc中调用Controller中的Route Provider服务

时间:2021-12-03 21:04:47

I am using controller in my Angularjs which gets question one by one from server and i want on specific condition this controller should call a routeprovider that should change my current view with templateUrl and put into a directive

我在我的Angularjs中使用控制器从服务器逐个问题,我希望在特定条件下这个控制器应该调用一个routeprovider,它应该用templateUrl改变我当前的视图并放入一个指令

my question is can i call route provider in controller rather than module

我的问题是我可以在控制器而不是模块中调用路由提供程序

here is my CreateController

这是我的CreateController

var CreateController = ['$scope', '$http', function ($scope, $http) {
$scope.model = {

    };
................>

.................>
    $scope.NextQuestion = function () {

        $http.post('/Testing/NextQuestion', {

            ........................>

        }).success(function (newdata) {
            $scope.model = newdata;
            var inccomplevel = $scope.model.servercomplevel;
            if (qId == 10) {
                  here i need the code for routeProvider and directive please provide me help
            }
......................>
    }];

i did the route provider in app.js file there it works

我在那里工作的app.js文件中做了路由提供程序

here is the code for app.js when i do like this it works and when i shift the code of route provider

这是app.js的代码,当我这样做时,它工作,当我转移路由提供商的代码

to the create controller in condition if qId == 10 there it does not work

如果qId == 10那么条件下创建控制器它不起作用

var app = angular.module('app', ['ngRoute']);
app.controller('CreateController', CreateController);

    app.config(function ($routeProvider) {
        $routeProvider
        .when('/',
        {
            templateUrl: 'Partials/TestCompleted.html',
            controller: 'AppCtrl'
        })
        .otherwise({ redirectTo: '/' });
    });
    app.controller("AppCtrl",function ($scope) {
        $scope.newmodel = {

        }
    });

1 个解决方案

#1


2  

Instead of trying to change the value of the templateUrl on the route, you should define another route. Then you can simply switch routes.

您应该定义另一条路线,而不是尝试更改路线上templateUrl的值。然后你可以简单地切换路线。

To change the route/view, you need update the path. You can do this using the $location service.

要更改路径/视图,您需要更新路径。您可以使用$ location服务执行此操作。

See AngularJS : How do I switch views from a controller function?

请参阅AngularJS:如何从控制器功能切换视图?

#1


2  

Instead of trying to change the value of the templateUrl on the route, you should define another route. Then you can simply switch routes.

您应该定义另一条路线,而不是尝试更改路线上templateUrl的值。然后你可以简单地切换路线。

To change the route/view, you need update the path. You can do this using the $location service.

要更改路径/视图,您需要更新路径。您可以使用$ location服务执行此操作。

See AngularJS : How do I switch views from a controller function?

请参阅AngularJS:如何从控制器功能切换视图?