gpt4 book ai didi

javascript - 在 AngularJS ng-submit 中提交表单后如何绑定(bind) View ?

转载 作者:行者123 更新时间:2023-11-29 18:11:53 25 4
gpt4 key购买 nike

我有一个简单的问题。在 AngularJS 中提交表单后如何绑定(bind) View ?我的 Controller 有这个功能来测试提交是否有效:

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

在ng-submit通过后如何把alert("awesome!");改成ui-view?我有一个名为 registration-share.php 的 ui-view。

更新:我在提交按钮中调用 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 注入(inject) Controller 并使用以下内容:

$state.go('newUiRouterStateYouWishToDisplay');

这在这一点上不适用,因为你澄清说你正在使用 ui-router,但是如果您使用的是 ngRoute,请将 $location 注入(inject) Controller 并使用以下命令:

$location.path('/newNgRouteYouWishToDisplay');

关于javascript - 在 AngularJS ng-submit 中提交表单后如何绑定(bind) View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26644222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com