[英]How Do You Bind A View After Form Submit In AngularJS ng-submit?
我有一个简单的问题。 在AngularJS中提交表单后,如何绑定视图? 我的控制器具有以下功能来测试提交是否有效:
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');
};
}]);
您如何更改alert("awesome!");
ng提交通过后进入ui视图? 我有一个名为registration-share.php
的用户界面视图。
更新:我在提交按钮中调用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>
我的formApp包装程序如下所示:
<form id="signup-form" ng-submit="processForm()">
<!-- our nested state views will be injected here -->
<div id="form-views" ui-view></div>
</form>
在使用ui-router时, 将$ state注入控制器并使用以下命令:
$state.go('newUiRouterStateYouWishToDisplay');
这一点目前还不适用,因为您已经说明您正在使用ui-router,但是如果您使用的是ngRoute,请将$ location注入控制器并使用以下方法:
$location.path('/newNgRouteYouWishToDisplay');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.