Angular,从一个控制器重定向到另一个控制器

时间:2015-02-12 16:16:15

标签: angularjs node.js redirect

我正在使用从 https://github.com/firebase/angularfire-seed 项目开始的angularjs开发应用程序。我正试图从控制器重定向到另一个没有成功。我需要从控制器执行此操作,因为我在重定向之前有一些控件要做。我正在使用location对象来做.. ..

以下是我的重定向代码:

$scope.infostore = function() {
    $location.path( 'store' );
}

这是我的路线配置:

angular.module('myApp.routes', ['ngRoute'])    
    .config(['$routeProvider', function($routeProvider) {    
      $routeProvider.when('/home', {
         authRequired: true,
         templateUrl: 'partials/home.html', 
         controller: 'HomeCtrl'
      });    
      $routeProvider.when('/apps', {
         authRequired: true,
         templateUrl: 'partials/apps.html',
         controller: 'appsController'
      });    
      $routeProvider.when('/store', {
         authRequired: true,
         templateUrl: 'partials/store.html',
         controller: 'storeController'
      });    
      $routeProvider.otherwise({redirectTo: '/home'});    
   }]);

但是每当我在appsController中调用'infostore'方法时,我会将我重定向到'home'

为什么呢?我只是尝试在主范围内使用apply()而没有成功。

这是我的商店控制器:

'use strict';

app.controller('storeController', function($location, $firebase, $modal, $scope, database, $http, $rootScope, $routeParams) {

    var ref = database.returnRef("users/"+$rootScope.auth.user.uid+"/apps");
    $scope.apps = $firebase(ref);


});

这是商店html:

<div class="container">
    <br />
    <div class="row">

        <div class="col-md-12 text-center">
            <h3>
                <span>{{ 'myappslong' | translate }}</span>
            </h3>
        </div>

    </div>

    <br />
    <div class="row">

        <div class="col-md-1"></div>

        <div class="col-md-10">

            store

        </div>

        <div class="col-md-1"></div>

    </div>
</div>

以下是第一个控制器的网址:http://localhost:8000/app/index.html#/apps

1 个答案:

答案 0 :(得分:0)

解决了,我的html代码出错了。使用location.path可以正常工作。