2016-07-22 100 views
0

我正在自己做一个项目,练习我已经了解的有关MEAN堆栈的知识。在该项目中,我希望用户填写表单,并在将其保存到数据库中后,系统将其用于第二个表单以填充该表单等。我是前端的angularjs,并且在其中使用ui.route。出于某种原因,我的程序不会进入第二个程序。我已经阅读过有关同样问题的其他人,但我找不到我的算法出了什么问题。每个表单都可以很好地工作,或者当我从工具栏拨打电话时。试图在angularjs中从一种形式转到另一种形式

Frontend.js

angular 
    .module('authApp',['auth0', 'angular-storage', 'angular-jwt', 'ngMaterial', 'ui.router', 
      'AdminUser', 'appProfile', 'appToolbar', 'Mod-Company', 'ModShow']) 

    .config(function($provide, authProvider, $urlRouterProvider, $stateProvider, $httpProvider, jwtInterceptorProvider,$mdThemingProvider){ 

/* $mdThemingProvider.theme('docs-dark'); */ 
    $mdThemingProvider.theme('default') 
     .dark(); 

    $mdThemingProvider.alwaysWatchTheme(true); 

    authProvider.init({ 
    domain: 'workflowjobs.auth0.com', 
    clientID: 'SjzgRRh3w4ZEFRGLdglpJYvCPCkM189w' 
    }); 

    jwtInterceptorProvider.tokenGetter = function(store) { 
     return store.get('id_token'); 
    } 

    $urlRouterProvider.otherwise('/home'); 

    $stateProvider 
    .state('home', { 
     url: '/home', 
     templateUrl: 'components/home/home.html' 
    }) 
    .state('company', { 
     url: '/company', 
     templateUrl: 'components/company/company.html' 
    }) 
    .state('singlecompany', { 
     url: '/singlecompany', 
     templateUrl: 'components/singlecompany/singlecompany.html' 
    }) 
    .state('show', { 
     url: '/show', 
     templateUrl: 'components/show/show-form.html' 
    }) 
    .state('ticket', { 
     url: '/ticket', 
     templateUrl: 'components/ticket/ticket.html' 
    })   
    .state('useradmin', { 
     url: '/useradmin', 
     templateUrl: 'components/useradmin/useradmin.html' 
    }) 
    .state('user', { 
     url: '/user', 
     templateUrl: 'components/user/user.html' 
    })  
    .state('profile', { 
     url: '/profile', 
     templateUrl: 'components/profile/profile.html', 
     controller: 'profileController', 
     controllerAs: 'user'  
    }); 

从我使用控制器我需要,显示由用户填写表格,然后我所说的用户点击后addcompany()上的按钮以保存形式mongodb数据库上的文档。

<section class="table" ng-controller="CompanyCtrl"> 
    <form name="CompanyForm"> 
    ... 
    <input class="form-control" ng-model="company.name" size="40"> 
    ... 
    <p><md-button class="md-raised md-primary md-hue-1" ng-click="addcompany()" aria-label="next"> 

现在在这段代码中是我遇到问题的地方。在$ location.path( '/管理用户')不工作:

var app = angular.module('Mod-Company', []); 

app.controller('CompanyCtrl', ['$scope', '$http', 
          function($scope,$http){ 

       var refresh = function() { 
          $http.get('http://localhost:3001/api/company').success(function(response){ 

               $scope.companylist = response; 
               $scope.company = "";  
               }); 
             }; 

       refresh(); 



       $scope.addcompany = function(){ 
         $http.post('http://localhost:3001/api/company', $scope.company).success(function(response) { 

             refresh(); 

            $location.path('/useradmin'); 

             }); 
            $location.path('/useradmin'); 
         }; 
+0

你的代码是否抛出任何特定的错误从浏览器,IE浏览器的控制台..等等?另外,如果您打开开发人员工具并在“addcompany”中放置调试点,它是否被调用?我相信这样会更容易找到问题 –

+0

没有错误 – user3538384

+0

如果调试它,该方法是否被调用? –

回答

0

而不是使用$location.path('/useradmin');尝试$state.go('useradmin');的。

如果仍然没有工作,它会更容易帮助你,如果你可以分享在https://jsbin.comhttps://plnkr.co

+0

我试过了,它没有工作 – user3538384

+0

谢谢你帮助埃弗顿。 – user3538384