离子收音机按钮

时间:2016-09-27 02:42:59

标签: javascript angularjs ionic-framework radio-button

我似乎无法让这个工作。

这是我的HTML。

<input type="radio" ng-value="0" checked="{{value0}}"/>
    <label>Standard</label>

    <br>

<input type="radio" ng-value="1" checked="{{value1}}"/>
        <label>Hidden</label>

这是我的js。我所做的是呼叫端点。如果它返回0,则应检查标准。如果它返回1则应检查隐藏。

$http.get(www.website.com, {"headers": {authorization: strToken}}).success (function(response)
    { 

        console.log (angular.toJson (response))


        if (response==0)
        {
            $scope.value0=true
            console.log ('value is 0')

        }
        else if (response==1)
        {
            $scope.value1=true
            $scope.value0=false
            console.log ('value is 1')

        }


})

1 个答案:

答案 0 :(得分:0)

请在JS中执行以下操作:

$http.get(www.website.com, {"headers": {authorization: strToken}}).success (function(response)
    { 
        $scope.app= {}; //Blank object to interact with DOM
        $scope.app.value0 = false;
        $scope.app.value1 = false;
        console.log (angular.toJson (response))


        if (response==0)
        {
            $scope.app.value1=false;
            $scope.app.value0=true; //put your value in object which we created
            console.log ('value is 0')

        }
        else if (response==1)
        {
            $scope.app.value1=true; //put your value in object which we created
            $scope.app.value0=false; //put your value in object which we created
            console.log ('value is 1')

        }


})

并在您的HTML中:

<input type="radio" ng-value="0" checked="{{app.value0}}"/>
    <label>Standard</label>

    <br>

<input type="radio" ng-value="1" checked="{{app.value1}}"/>
        <label>Hidden</label>

或者您也可以使用这样的方式而不使用括号:

<input type="radio" ng-value="0" checked="app.value0"/>
    <label>Standard</label>

    <br>

<input type="radio" ng-value="1" checked="app.value1"/>
        <label>Hidden</label>

希望它会对你有所帮助。