这里是代码片段
的index.HTML
<!DOCTYPE HTML><HTML ng-app="scotchApp"><head> <script src="angular.min.Js"></script> <script src="angular-route.min.Js"></script> <script src="script.Js"></script></head><body ng-controller="mainController"> <nav > <div ></div> <ul > <li><a href="#"><i ></i> Home</a></li> <li><a href="#about"><i ></i> About</a></li> <li><a href="#contact"><i ></i> Contact</a></li> </ul> </div> </nav> <div ID="main"> <div ng-vIEw></div> </div></body></HTML>
home.HTML的
<div > <h1>Home Page</h1> Billing index : <input type="text" ng-model='billingMapValue'> <br/><br/> Billing value : {{billingMap[billingMapValue]}} <ng-click=navigate() type="button" value='submit'> <p>{{ message }}</p></div>
about.HTML
<div > <h1>About Page</h1> <p>{{ message }}</p></div>
的script.Js
var scotchApp = angular.module('scotchApp',[ 'ngRoute' ]);scotchApp.config(function($routeProvIDer) { $routeProvIDer .when('/',{ templateUrl : 'home.HTML',controller : 'mainController' }) .when('/about',{ templateUrl : 'about.HTML',controller : 'mainController' }) .when('/contact',{ templateUrl : 'contact.HTML',controller : 'mainController' });});scotchApp.controller('mainController',function($scope) { $scope.message = 'Everyone come and see how good I look!'; $scope.billingMapValue = ""; $scope.billingMap = new Array(); $scope.billingMap["ZF2"] = "Invoice"; $scope.billingMap["ZRE"] = "Credit for Returns"; $scope.billingMap["ZG2"] = "Credit Memo"; $scope.billingMap["ZL2"] = "Debit Memo"; $scope.billingMap["ZS2"] = "Cancellation of Credit Memo"; $scope.billingMap["ZS1"] = "Cancel. Invoice (S1)";});
现在我需要的是.如果我运行index.HTML页面,我将在主页上有一个输入文本框.如果输入一些索引值,如’ZF2′,我会看到值“invoice”.页面顶部会有超链接列表.home,.about和.contact.我将点击关于项目然后我导航到关于页面.然后我通过单击主页超链接再次导航到主页,现在我需要查看我输入并获得的先前数据.如何做到这一点?
提前致谢.
您需要对代码进行一些更改.
>您需要将所有静态移动到服务或角度常量.
>在绑定对象时使用dot rule,该对象将自动更新绑定.
>为每个视图分配不同的控制器,这将是更模块化的方法.
服务
scotchApp.service('dataService',function() { this.data = {} this.data.billingMap = new Array(); this.data.billingMap["ZF2"] = "Invoice"; this.data.billingMap["ZRE"] = "Credit for Returns"; this.data.billingMap["ZG2"] = "Credit Memo"; this.data.billingMap["ZL2"] = "Debit Memo"; this.data.billingMap["ZS2"] = "Cancellation of Credit Memo"; this.data.billingMap["ZS1"] = "Cancel. Invoice (S1)"; this.data.selectedBillMap = '';});
调节器
scotchApp.controller('mainController',function($scope,dataService) { $scope.message = 'Everyone come and see how good I look!'; $scope.billingData = dataService.data.billingMap;});
Demo Plunkr
总结以上是内存溢出为你收集整理的html – 如何在AngularJS中从page2导航后保留page1的输入数据全部内容,希望文章能够帮你解决html – 如何在AngularJS中从page2导航后保留page1的输入数据所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)