参数没有传递到下一页- AngularJS
Parameter not passed to next page - AngularJS
我想在点击按钮时传递一个参数给下一页。
我试过如下;在第一页上,我有一个文本区,我想把这个值传递给下一页的按钮点击使用AngularJS,我已经尝试如下,但它不工作。
index . html
<!doctype html>
<html ng-app="project">
<head>
<title>Angular: Service example</title>
<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<script src="sample.js"></script>
</head>
<body>
<div ng-controller="FirstCtrl">
<h2>{{name}}</h2>
<input ng-model="thing.x"/>
</div>
<input type="button" value="send" onclick="send()">
<script>
function send(){
window.location ="second.html";
}
</script>
</body>
</html>
sample.js
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
var projectModule = angular.module('project',[]);
projectModule.factory('theService', function() {
return {
thing : {
x : 100
}
};
});
function FirstCtrl($scope, theService) {
$scope.thing = theService.thing;
$scope.name = "First Controller";
}
function SecondCtrl($scope, theService) {
$scope.someThing = theService.thing;
$scope.name = "Second Controller!";
}
second.html
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>Passed data</title>
<script src="sample.js"></script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
</head>
<body>
<div ng-controller="SecondCtrl">
<h2>{{name}}</h2>
<input ng-model="someThing.x"/>
</div>
<br>
</body>
</html>
你能帮我弄明白吗?
先读这个https://docs.angularjs.org/guide/$location
Remove send() function
function FirstCtrl($scope, $location, theService) {
$scope.thing = theService.thing;
$scope.name = "First Controller";
$scope.send = function(){
$location.path('/second').search({id: 12});
};
}
<input type="button" value="send" ng-click="send()">
要将参数发送到下一页,必须使用$location
服务。
$location.path('/second').search({id: 12});
但是这不会为你工作,因为你不是使用AngularJS路由,你是使用JS。我建议按照这个PhoneCatApp来学习Angular基础知识
相关文章:
- 如何获取不属于我项目的上一页的URL
- 如何在Facebook上的iframe应用程序中使后退按钮返回到上一页
- 使用Booklet Jquery插件,我如何验证最后一页是否显示
- 如何在一页网站中使用PHP重定向到一个页面
- Javascript并不是显示在每一页上
- 如何在一页上显示多个Highcharts图表
- jQuery分页下一页和上一页按钮在点击零或超过最后一页后失败
- 如何为AngularJS制作智能表中第一页和最后一页的跳过按钮
- Bootstrap一页导航Fluid网站最小化问题
- 返回上一页时,Javascript仍处于活动状态
- 如何在angularjs应用程序中注销后,通过浏览器后退按钮禁止用户访问上一页
- Angularjs:目录分页控件没有'即使按下页面按钮,也不会显示下一页
- 用angularjs将id从一页传递到另一页
- 如何在不刷新 angularjs 的情况下返回上一页
- "一页应用程序“;DOM操作而不是AngularJS
- 一页angularjs的单独背景图像
- Angularjs:从api获取下一页按钮
- 在angularjs中,点击一个链接后给下一页传递一个ID
- 参数没有传递到下一页- AngularJS
- 使用jquery(而不是angularjs)返回前一页而不刷新