[英]angularjs how to access mulitple input fields from a form inside controller
How do I access the individual input names defined in a form inside my controller? 如何访问控制器内部表单中定义的各个输入名称?
rates.rateName
rates.rateBitrate
rates.rateWidth
rates.rateHeight
This does not work: var url = {{ tmp + data.rateName }};
这不起作用:var url = {{tmp + data.rateName}};
I need to extract one of the input values from the form and append it to the url to be used with a $http POST. 我需要从表单中提取输入值之一,并将其附加到与$ http POST一起使用的url中。 I need to put the rest of the inputs from the form (all together) into the POST as well as json blob.
我需要将表单的其余输入(全部)放入POST以及json blob。
<div ng-controller="RateCtrlAdd"> <rd-widget> <rd-widget-header icon="fa-users" title="Rates"> </rd-widget-header> </rd-widget> <p></p> <div class="row"> <div class="col-sm-6"> <form name="myForm" ng-submit="SendData()"> <input class="form-control input-lg" type="text" placeholder="rate name" name="rates.rateName" ng-model="rates.rateName" required/> <br> <input class="form-control input-lg" type="text" placeholder="rate bit rate" name="rates.rateBitrate" ng-model="rates.rateBitrate" required/> <br> <input class="form-control input-lg" type="text" placeholder="rate width" name="rates.rateWidth" ng-model="rates.rateWidth" required/> <br> <input class="form-control input-lg" type="text" placeholder="rate height" name="rates.rateHeight" ng-model="rates.rateHeight" required/> </form> </div> </div> <div class="row" style="margin-top: 12px;"> <div class="col-sm-6"> <button class="btn btn-success btn" value="Send" ng-click="SendData()"> Add </button> <a href="/rates" class="btn btn-danger btn"> Cancel </a> </div> </div> </div>
'use strict'; angular.module('RDash') .controller('RateCtrlAdd', ['$scope', '$http', function($scope, $http) { console.log('RateCtrlAdd - enter...'); $scope.SendData = function () { var data = $scope.rates; console.log('RateCtrlAdd - rates from input form: ', $scope.rates); var tmp = 'http://10.10.15.145:8085/lms/outputstream/'; var url = {{ tmp + data.rateName }}; console.log('RateCtrlAdd - url: ', url); }; // end function() console.log('RateCtrlAdd - ...exit'); }]); // end controller()
You cant use binding expression ie {{}}
in controller. 您不能在控制器中使用绑定表达式,即
{{}}
。 Add it using simple javascript 使用简单的javascript将其添加
Try this 尝试这个
var url = tmp + data.rateName;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.