私はStackOverFlowをかなり徹底的に検索しましたが、私の答えは見つかりませんでした。AngularJS-オートフィルのドロップダウンで前のページの情報
私はドロップダウンメニューを持つフォームを持っています。また、ユーザーがボタンをクリックすると、新しいHTMLページに移動して詳細情報を入力します。しかし、私はどのように私のデータをドロップダウンメニューから次のページに渡し、私は両方のページのフォームに同じコントローラを使用している場合、選択されたオプションで同じドロップダウンメニューを自動入力するのですか?
var app = angular.module('myApp', []);
var currentEquipmentType = "";
app.controller('myController', ['$scope', function($scope) {
$scope.addEquipment.type = "";
$scope.addEquipment.name = "";
$scope.typeList = ['A', 'B', 'C', 'D'];
//trying to get this info passed onto the next page.
if (sessionStorage.type) {
currentEquipmentType = sessionStorage.type;
}
$scope.getEquipmentInfo = function() {
if ($scope.addEquipment.name !== undefined) {
sessionStorage.name = $scope.addEquipment.name;
sessionStorage.type = $scope.addEquipment.type;
} else {
// warning message
}
}
}]);
<input type="text" ng-model="addEquiment.name">
<select ng-model="addEquipment.type" ng-options="type for type in typeList">
<option value="" selected="selected">Please select a type.</option>
</select>
<!-- on the next page (different html file, but uses the same controller as the previous page) -->
<!-- more form inputs here -->
<select ng-model="addEquipment.type" ng-options="type for type in typeList">
<option>NEED THE OPTION SELECTED FROM PREVIOUS PAGE</option>
</select>
ありがとうございます。これは間違いなくコードをきれいにしますが、私の質問にはまだ答えがありません。言って、私の選択ボックスはindex.htmlとnextPg.htmlにあります。インデックス。htmlには、nextPg.htmlに1つかかるボタンもあります。 index.htmlで「B」を選択した場合、nextPg.htmlで「B」を永続化するにはどうすればよいですか? –
このディレクティブは、あなたのアプリケーションがあるmain.jsに置き、すべてのページでglobalを使用します。 「
」 –を試しました。私はそれが動作するとは思わない...? –