1

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

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

here is my 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

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

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

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 = {

        }
    });
5
  • I think is not clear your issue or question, please re-raise Commented Jan 9, 2015 at 17:17
  • 3
    Instead of editing a question to ask another completely unrelated question, simply ask another question. I would suggest reverting your edits. No one see this question and won't be of any help to you. Commented Jan 29, 2015 at 17:26
  • 1
    It's entirely unfair to @DouglasLudlow and the time he spent working on your question to change it like you did here. Please do not do that again. Commented Jan 29, 2015 at 18:38
  • I did not get the answer thats why I changed Commented Jan 30, 2015 at 7:50
  • and I can't ask any more question in stack over flow that's why i edit the Question Commented Jan 30, 2015 at 7:52

1 Answer 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.

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

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.