如何获得它们在单选按钮,点击后选择的值列表对角的js提交 [英] How to get list of values which are selected in radio button after click on submit in Angular js

查看:213
本文介绍了如何获得它们在单选按钮,点击后选择的值列表对角的js提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是HTML,此文件在哪里局部全局控制器在主页中定义:消息对象包含了从第一页加载的数据

Here is the HTML, this file is partial where global controller is defined in home page:message object contains data which is loaded from first page .

<ng-repeat data in message>
<input type="radio"  ng-model="accountValue"  value="{{data}}" name="select" />

{{data.Type}}
{{data.Number}}

继续

JS:

myApp.controller('myCtrl',['$scope',function ($scope) {
    $scope.selectAccount = function(id) {
        alert(id);
    }
}]);

我收到ID为未定义。请帮忙。谢谢

I am getting id as undefined . Please help. thanks

推荐答案

那么按什么你到底需要的意见是分享两个控制器(即全局和myCtrl)上的onclick的继续按钮之间的数据。有些情况下,你可以做同样的各种方式。

So as per the comments what you exactly need is to share the data between two controllers (i.e Global and myCtrl ) on onclick of continue button. There are various ways in which you can do the same.

打造,以维持你的共享对象和控制器,只是在这种情况下,reference.Please音符处理它会工作,直到你会不会刷新页面手动按照理想情况下的服务。如果你的数据是不是更重,并且需要保持它的所有网页比在这种情况下,你可以将其存储在localStorage的。

Build the service which maintain your shared object and the controllers just handle with the reference.Please note in this case it will work untill you will not refresh your page manually as per the ideal circumstances. If your data is not more heavy and you require to maintain it across all pages than in this case you can store it in localstorage.

Here is the demo http://plnkr.co/edit/rrFTmtnYjYNjyE8twUif

您可以做到用服务与同样的东西; $范围。$表的方法。我preFER你不使用$分配看,看你应该只需要使用的setter /吸气访问和整个服务对this.Instead共享数据。

You can do the same things by using service & $scope.$watch method. I prefer you do not use $watch for this.Instead of assigning and watching entire service you should just needs to use setter/getter to access and share data.

Here is the demo http://plnkr.co/edit/N2qIMRyDj2SX2BdBleU4

是的,你也可以使用使用NG-模型范围的$ parent属性。当然,还有几种方法你可以做同样的事情:假设你的HTML是像下面

Yep you can also use the $parent property of the scope using ng-model. There are certainly several ways in which you can do the same things: Let's say your HTML is like below

<div ng-controller="ParentCtrl">
   <div ng-controller="ChildCtrl"></div>
</div>

然后就可以像这样访问你的父母范围

Then you can access your parent scope like this

function ParentCtrl($scope) {
$scope.cities = ["NY", "Amsterdam", "Barcelona"];
}
function ChildCtrl($scope) {
  $scope.parentcities = $scope.$parent.cities;
}

事实上,因为你定义城市的家长控制孩子的控制器将继承所有范围的变量。所以theoritically你不必调用$父。上述例子也可写成如下:

Actually since you defined cities in the parent controller your child controller will inherit all scope variables. So theoritically you don't have to call $parent. The above example can also be written as follows:

function ParentCtrl($scope) {
$scope.cities = ["NY","Amsterdam","Barcelona"];
}
function ChildCtrl($scope) {
$scope.parentCities = $scope.cities;
}

href=\"https://docs.angularjs.org/guide/scope\" rel=\"nofollow\"> 都采用这种做法。角文档的

The Angular Docs are using this approach.

这篇关于如何获得它们在单选按钮,点击后选择的值列表对角的js提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆