2016-06-10 114 views
0

我的动态生成的单选框在html中的列表:Angularjs - 无法选择的单选按钮值传递给控制器​​

**index.html** 

    <div id="choiceGraphId1" class="radio-button" ng-controller="selectGraph1"> 
     <div ng-repeat="choice1 in choices1"> 
     <table> 
      <label class="labelClass" > <td > {{choice1.graphChoice1}} </td> </label> <td>&nbsp </td> <label class="labelClass" > <td> <input type="radio" ng-model="$parent.selectedGraph1" ng-value="choice1.graphChoice1" name="graphChoice1" required /> </td> </label></table></div></div> 

    Angular Controller: 
    app.controller('selectGraph1', function ($scope,$rootScope) { 

     $rootScope.selectedGraph1="Choice1"; 

     $rootScope.choices1 = [{ 
      graphChoice1: "Choice1" 
     }, { 
      graphChoice1: "Choice2" 
     } 
     ]; 


     alert($rootScope.selectedGraph1); 

    }); 

I want to pass the value of $rootScope.selectedGraph1 to 
PrintReportToPDF controller : 


**index.html** 
    <div class="buttonsClass" ng-controller="**PrintReportToPDF**"> 
            <button popover="Click button to open selected date range PDF Report in a new tab" 
              popover-trigger="mouseenter" type="button" class="btn btn-info" 
              ng-disabled="dataLoading" 
              ng-click="PrintReportToPDF()"> 
             <i class="fa fa-file-pdf-o icon"></i> 
             Preview PDF Report 
            </button> 


... 
app.controller('PrintReportToPDF', function($scope, $rootScope, $window, UrlServices , StatsByDatePDF, StatsByDateExcel, Flash) { 

    //Preview PDF Report 

    alert($rootScope.selectedGraph1); 
    alert($rootScope.selectedGraph2); 

    $scope.PrintReportToPDF_1_StatisticsByDate = function() { 
    .... 

我试图访问$rootScope.selectedGraph1在我的控制器 但其价值是不确定的在PrintReportToPDF控制器中。 我在这里做错了什么?

回答

0

你可以找到你的解决方案here

var myApp = angular.module('myApp',[]); 
myApp.factory('UserService', function() { 
    return { 
     name : 'anonymous' 
    }; 
}); 

function MyCtrl($scope, UserService) { 
    $scope.name = UserService.name; 
} 
相关问题