$ conditional non-angular scope

1

Hello

I have these radio buttons:

  <div class="row" ng-controller="GetDados">
            <div class="col-lg-10 col-lg-offset-5">
                <label class="radio-inline">
                  <input type="radio" name="optradio" ng-bind="pizza">Pizza
                </label>
                <label class="radio-inline">
                  <input type="radio" name="optradio" ng-bind="barras">Barras
                </label>
            </div>
        </div>

That's the idea ..

edit:

What I need is that when choosing a radio button angular take an action, such as displaying a graph through $ scope

edit:

I tried this, it worked:

<div class="row" ng-controller="GetDados">
            <div class="col-lg-10 col-lg-offset-5">
                <label class="radio-inline">
                  <input type="radio" name="optradio" ng-click="pizza()" >Pizza
                </label>
                <label class="radio-inline">
                  <input type="radio" name="optradio" value="barra()" >Barras
                </label>
            </div>
        </div>



app.controller('GetDados', function($scope, $http){

    $http.get('http://localhost/api/v1/index.php/dados').
        success(function(data){
        $scope.dados = data;
    });    

    $scope.pizza = function() {
        console.log("oi");
    } 
});
    
asked by anonymous 17.05.2016 / 19:13

1 answer

0

You can use a single function in ng-click and check which radio was clicked through $ scope this way:

<div class="row">
        <div class="col-lg-10 col-lg-offset-5">
            <label class="radio-inline">
              <input type="radio" name="optradio" ng-model="escolha" value="pizza" ng-click="getInfo()">Pizza
            </label>
            <label class="radio-inline">
              <input type="radio" name="optradio" ng-model="escolha" value="barras" ng-click="getInfo()">Barras
            </label>
        </div>
    </div>

In the controller it would look something like this:

app.controller('GetDados', function($scope, $http){
    $scope.getInfo = function(){
        $http.get('http://localhost/api/v1/index.php/dado').then(function(data){
            console.log(data);
            if($scope.escolha == "pizza"){
                console.log($scope.escolha);
            }
            else{
                console.log($scope.escolha);
            }               
        }, function(err){
            console.log(err);
        });
    }
} );
    
17.05.2016 / 20:24