我想在变量中设置已检查的radiobutton
的值。但我无法得到它。下面是我试过的代码
master.controller('FiberLead_Filter', function($scope, $http, NEIQC_Service, Scopes, $rootScope) {
var rdSelectMP = $scope.MPSelect; // here I am getting undefined
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.25/angular.min.js"></script>
<div class="rightFilter" ng-controller="FiberLead_Filter as Filter" id="FiberLead_Filter">
<div class="pdfDownload customeRadioWrap">
<div class="customeRadio">
<input type="radio" id="btnCurrentMP" name="radio-group" ng-model="MPSelect" ng-value="Current">
<label for="btnCurrentMP">Current MP</label>
</div>
<div class="customeRadio">
<input type="radio" id="btnAllMP" name="radio-group" ng-model="MPSelect" ng-value="All">
<label for="btnAllMP">All MP</label>
</div>
<button class="btn btn-default customBtn" ng-click="DownloadExcelReport()"><i class="fa fa-file-pdf-o" aria-hidden="true"></i> Download</button>
</div>
</div>
让我知道我的代码有什么问题,因为我得到它UNDEFINED
这是因为ng-value
正在寻找“全部”$scope
变量,但可能没有。如果期望值是字符串,则使用'All'
或者使用value
。
下面的工作小提琴,单击“下载”按钮以记录当前值(首先选择一个值)。
angular.module('app', []);
angular.module('app').controller('FiberLead_Filter', function($scope, $http, $rootScope) {
$scope.DownloadExcelReport = function(){
console.log($scope.MPSelect);
}
}
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.25/angular.min.js"></script>
<div ng-app="app">
<div class="rightFilter" ng-controller="FiberLead_Filter as Filter" id="FiberLead_Filter">
<div class="pdfDownload customeRadioWrap">
<div class="customeRadio">
<input type="radio" id="btnCurrentMP" name="radio-group" ng-model="MPSelect" value="Current">
<label for="btnCurrentMP">Current MP</label>
</div>
<div class="customeRadio">
<input type="radio" id="btnAllMP" name="radio-group" ng-model="MPSelect" value="All">
<label for="btnAllMP">All MP</label>
</div>
<button class="btn btn-default customBtn" ng-click="DownloadExcelReport()"><i class="fa fa-file-pdf-o" aria-hidden="true"></i> Download</button>
</div>
</div>
</div>