gpt4 book ai didi

javascript - 提交表单时如何调用不同的 View ?

转载 作者:行者123 更新时间:2023-11-28 06:51:17 24 4
gpt4 key购买 nike

我有index.html 文件,其中包含以下代码。我想在提交表单时向其他 View searchResult.html 显示结果。我在 homeCtrl 中检索表单数据,但在提交表单时无法将检索到的数据显示到 searchResult.html 页面。请帮助我。

<!DOCTYPE html>
<html ng-app="myApp">
<head>
//head code...
</head>
<body ng-controller="homeCtrl">
<form ng-submit="doSearch()">
<input type="search" placeholder="From" ng-model="search.from">
<input type="search" placeholder="Destination" ng-model="search.to">
<button type="submit">Search</button>
</form>

<div ng-view></div>
</body>
</html>


var app = angular.module('myApp', [])
app.controller('homeCtrl', function($scope, $location) {
$scope.doSearch = function() {
$scope.search={};
$scope.search=$scope.search;
//retrieved data here
}
});

最佳答案

您可以在homeCtrl中获取数据并将其存储在rootscopelocalstorage中,然后将页面重定向到搜索页面并从检索数据>rootscopelocalstoragesearchCtrl 范围。

关于javascript - 提交表单时如何调用不同的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32941750/

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