如何在ngClick上获取参数。然后,触发指令以丁胺方式注入模板

时间:2022-12-02 15:59:11

I need to inject new template dynamically depending on the value or parameter of radio button.
This is my HTML

我需要根据单选按钮的值或参数动态注入新的模板。这是我的HTML

 <div class="container-fluid" ng-app="rjApp">
        <div class="panel-body" ng-controller="mainController"> 
             <input name="penanggung_biaya"  type="radio"  ng-model="checked"  ng-click="broadcast(umum)" class="ace" value="umum"> <!-- I though, umum is the parameter which I want passed through to the Controller   -->     
             <input name="penanggung_biaya"  type="radio" ng-model="checked" ng-click="broadcast(instansi)" class="ace" value="instansi"> 

<example-directive message="message"> </example-directive> 

       </div>
 </div>

and, this is the JS

这是JS

   var rjApp = angular.module('rjApp',[]);
    rjApp.config(function($interpolateProvider) {
      $interpolateProvider.startSymbol('{::');
      $interpolateProvider.endSymbol('::}');
    })


//mainCotroller, should be work by ngClick through radio button 
    function mainController($scope, $rootScope) { 
        $scope.broadcast = function(event){
        console.log(event) //I've been thought, this is the part to passing the parameter of radio button, but not gonna works.
            $rootScope.$broadcast('handleBroadcast'); 
        };
    }


//the Directive, should be injected dinamically template, depends on ngClick parameter inside radion button  
    rjApp.directive('exampleDirective', function() {
        return {

            restrict: 'E',
            scope: {
                message: '='
            },
            link: function(scope, elm, attrs) {
                scope.$on('handleBroadcast', function(doifq) {  
                    templateUrl= '<?php echo url("registrasi/rawat_jalan/penanggung_biaya/") ?>'+doifq //This is the part to injected the dinamically template. And I've been guess the **doifq**, is the paramter to passing by the mainController
                });                     
            },
        };
    });

Please, somebody help me.
Regards.

请别人帮助我。的问候。

1 个解决方案

#1


0  

In broadcast, you could pass the parameter, 
  $scope.broadcast = function(event){
        console.log(event);
        $rootScope.$broadcast('handleBroadcast',event); 
  };
This way you would be getting doifq value in directive depending on the which radio button is clicked.

#1


0  

In broadcast, you could pass the parameter, 
  $scope.broadcast = function(event){
        console.log(event);
        $rootScope.$broadcast('handleBroadcast',event); 
  };
This way you would be getting doifq value in directive depending on the which radio button is clicked.