Need to Default select an Angular JS Radio Button

后端 未结 3 1843
刺人心
刺人心 2021-01-19 01:00

I am new to Angular JS and I am trying to create a set of radio buttons. Creating the buttons was the easy part, but I am having problems figuring out how to default select

3条回答
  •  心在旅途
    2021-01-19 01:39

    HTML

    
        
        

    JS

    angular.module('demoApp', []).
    controller('DemoController', function ($scope) {
        //moved init logic to controler
        $scope.price_options = [{
            qty: 1,
            price: 10,
            qty_description: 'descrip 1',
            discount: '1%',
            deal_value: 200
        }, {
            qty: 2,
            price: 7,
            qty_description: 'descrip 2',
            discount: '5%',
            deal_value: 100
        }];
        $scope.selected_price_option = $scope.price_options[1];
    });
    

    Forked fiddle: http://jsfiddle.net/W8KH7/2/

    Or you can use the object strategy to avoid having to reference $parent: http://jsfiddle.net/W8KH7/3/

提交回复
热议问题