$Conditional Room at Angle

Asked

Viewed 241 times

1

Hello!

I got 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 the angular perform an action, such as displaying a chart 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");
    } 
});
  • What error shows on console? Format your question, there is a part of the code that went wrong

  • Edited question

  • Why don’t you use ng-Click and put your function to run?

  • that’s what I tried...

  • "I tried this, it worked:". So that’s good. Because you’re asking?

1 answer

0

You can use a single ng-click function 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>

controller 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);
        });
    }
} );

Browser other questions tagged

You are not signed in. Login or sign up in order to post.