Durga Dutt
Durga Dutt

Reputation: 4113

Angular view loading

I am unable to load view using "$location.path" Although my browser URLis getting updated but my content is not getting loaded. Here is the controller code:

var app= angular.module("LoginModule",[]);
app.controller("LoginController",['$scope','$http','$location',function($scope,$http,$location){
        $scope.submitForm= function(valid){
            if(valid){
               $http.get('/admin/dashboard').success(function(data){
                $location.path('dashboard');
                });
            }
        };
}]);

It is changing my URL to "http://example.com/admin#/dashboard" for the same page. My router file code is:

var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/admin', function(req, res) {
  res.render('admin/login', { title: 'Login' });
});


router.get('/admin/dashboard', function(req, res) {
    //res.render('admin/dashboard', { title: 'Welcome to dashboard' });
    res.send("success");
});

module.exports = router;

Please advise I am doing anything wrong.

Upvotes: 0

Views: 171

Answers (1)

Mike
Mike

Reputation: 1246

Per the AngularJS docs at https://docs.angularjs.org/api/ng/service/$location :

Note: Path should always begin with forward slash (/), this method will add the forward slash if it is missing.

so, you need to put the full value in there:

$location.path('/admin/dashboard');

instead of

$location.path('dashboard');

Upvotes: 2

Related Questions