【问题标题】:trying to go from one form to another in angularjs试图在angularjs中从一种形式转到另一种形式
【发布时间】:2016-11-25 18:41:53
【问题描述】:

我正在自己制作一个项目来练习我所学到的关于 MEAN 堆栈的知识。在项目中,我希望用户填写一个表格,并将其保存在数据库中后,系统可以使用第二个表格来填写它等等。我是前端的 angularjs,我在其中使用ui.route。由于某种原因,我的程序没有进入第二个程序。我已经读到其他人有同样的问题,但我找不到我的算法有什么问题。每个表单都可以单独运行,或者当我从工具栏拨打电话时。

前端.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('/adminuser') 不起作用:

    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');
                         };

【问题讨论】:

  • 它是否会从 Chrome、IE.. 等的控制台中抛出任何特定错误?另外,如果您打开开发人员工具并在您的addcompany 中放置一个调试点,它会被调用吗?我相信这样会更容易找到问题
  • 没有错误
  • debug的方法是否被调用?

标签: angularjs node.js forms


【解决方案1】:

不要使用$location.path('/useradmin'); 试试$state.go('useradmin');

如果仍然无法正常工作,如果您可以在https://jsbin.comhttps://plnkr.co 中分享您的代码,会更容易为您提供帮助

【讨论】:

  • 感谢您帮助埃弗顿。
猜你喜欢
  • 2010-10-06
  • 1970-01-01
  • 2011-03-09
  • 1970-01-01
  • 1970-01-01
  • 2020-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多