簡體   English   中英

從廣播到$ http.post的AngularJS值

[英]AngularJS value from radio to $http.post

我想問你如何從廣播中獲取價值,並使用AngularJS與$ http.post一起發送。 這是一些例子

的HTML

  <input name="group1" type="radio" id="test1" value="4"/>
  <label for="test1">Four paintings</label>

  <input name="group1" type="radio" id="test2" value="6" />
  <label for="test2">Six paintings</label>

  <button ng-click="submit()">Submit</button>

一個單選按鈕的值為4,另一個為6。我想將這些數字發送給Angular,然后再發送給DB

角度的

$scope.submit = function(){
  if ( radioValue == 4 ) {
     $http.post(apiURL, {
        numberOfpaintings: ??, // radioValue
        ...      
       });
   } else if( radioValue == 6 ) {
     $http.post(apiURL, {
        numberOfpaintings: ??, // radioValue
        ...
       });
   }
}

那個“ radioValue”僅僅是一些應該通過radioButtons存儲的值組成的值。 謝謝!

這樣嘗試

柱塞: http ://plnkr.co/edit/b3AAr9XlVcS0IW962tUT

在腳本中:

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope,$http) {
  $scope.paintings = 4;

  $scope.submit = function(){

  alert($scope.paintings);

 $http.post(apiURL, {
    numberOfpaintings: $scope.paintings
   });
 }
});

在HTML

<body ng-controller="MainCtrl">

<input name="group1" ng-model="paintings" type="radio" id="test1" value="4"/>
<label for="test1">Four paintings</label>

<input name="group1"  ng-model="paintings" type="radio" id="test2" value="6" />
 <label for="test2">Six paintings</label>

<button ng-click="submit()">Submit</button>


</body>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM