Need to Default select an Angular JS Radio Button

后端 未结 3 1846
刺人心
刺人心 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:58

    Try this approach:

    angular.module('demoApp', []).controller('DemoController', function ($scope) {
        $scope.priceOptions = [
            {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 = {priceOption: $scope.priceOptions[0]};
    });
    

    HTML

    
    
    • {{ selected.priceOption.price }}
    • {{ selected.priceOption.discount }}
    • {{ selected.priceOption.deal_value }}

    Demo: http://jsfiddle.net/qWzTb/313/

提交回复
热议问题