简体   繁体   English

在AngularJS ng-submit中提交表单后,如何绑定视图?

[英]How Do You Bind A View After Form Submit In AngularJS ng-submit?

I have a simple question. 我有一个简单的问题。 How do you bind a view after form submit in AngularJS? 在AngularJS中提交表单后,如何绑定视图? My controller has this function to test if the submission works: 我的控制器具有以下功能来测试提交是否有效:

var spinnrApp = angular.module('spinnrApp', ['ngAnimate', 'ui.router', 'slick']);

spinnrApp.config(function ($stateProvider, $urlRouterProvider) {
  //
  // Now set up the states
  $stateProvider
    .state('registration', {
      url: "/registration",
      templateUrl: "app/components/registration/registration.php",
      controller: "FormController"
    })
    .state('registration.spinnrapp', { // nested state for the registration form
      url: "/spinnrapp", // url will be nested /registration/artist
      templateUrl: "app/components/registration/partials/registration-profile.php"
    })
    .state('registration.artist', { // nested state for the registration form
      url: "/artist", // url will be nested /registration/artist
      templateUrl: "app/components/registration/partials/registration-artist.php"
    })
    .state('registration.share', { // each nested state will have their own view
      url: "/share", // url will be nested /registration/share
      templateUrl: "app/components/registration/partials/registration-share.php"
    });
    //
    // For any unmatched url, redirect to /
    $urlRouterProvider.otherwise("/registration/spinnrapp");
});
spinnrApp.controller('FormController', ['$scope', '$http', function (scope, http){

  // get list of cities and store it to select
  http.get('cities.json').success(function(data){
    scope.cities = data;
  })

  // we will store all our form data in this object
  scope.formData = {};

  // function to process the form
  scope.processForm = function() {
    $state.go('registration.share');
  };
}]);

How do you change alert("awesome!"); 您如何更改alert("awesome!"); to a ui-view after ng-submit passes through? ng提交通过后进入ui视图? I have a ui-view called registration-share.php . 我有一个名为registration-share.php的用户界面视图。

UPDATE: I am calling the processForm in the submit button like this: 更新:我在提交按钮中调用processForm ,如下所示:

<div class="form-group row">
  <div class="col-xs-3 col-xs-offset-1">
    <button type="submit" class="submit btn">Next Section</button>
  </div>
</div>

where my formApp wrapper goes like this: 我的formApp包装程序如下所示:

<form id="signup-form" ng-submit="processForm()">
  <!-- our nested state views will be injected here -->
  <div id="form-views" ui-view></div>
</form>

As you're using ui-router, inject $state into the controller and use the following: 在使用ui-router时, 将$ state注入控制器并使用以下命令:

$state.go('newUiRouterStateYouWishToDisplay');

This doesn't apply at this point, as you clarified that you're using ui-router, but if you were using ngRoute, inject $location into the controller and use the follwing: 这一点目前还不适用,因为您已经说明您正在使用ui-router,但是如果您使用的是ngRoute,请将$ location注入控制器并使用以下方法:

$location.path('/newNgRouteYouWishToDisplay');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM