1

ng-model was set up here so i could just pass filter into my function and get all user selections. I thought I could also use it to prefill/default the data too. It's not working. This is my controller:

.controller('ListCtrl', [
    '$scope', '$filter', '$location', 'context', 'breeze', 'Service',
    function ($scope, $filter, $location, context, breeze, Service) {
        $scope.pageLoaded = true;
        $scope.lists = [];
        $scope.DDL1 = '';
        $scope.filter = {
            fromDate: '2015-05-01',
            toDate: '',
            sales: false            
        };

I have html like this:

            <md-content ng-controller="ListCtrl" layout="column" flex class="md-padding">
                <md-tabs class="md-primary clearfix" md-selected="0" flex>              
                    <md-tab label="Lists">
                        <table><tr>
                                <td width="10%">From Date: </td>
                                <td width="40%"><input type="date" ng-model="filter.fromDate" value="{{filter.fromDate}}"/></td>
<td width="10%">SParts: </td>
                                <td width="40%">                                    
                                    <input type="radio" name="sales" ng-model="filter.sales" value="true"> yes
                                    <input type="radio" name="sales" ng-model="filter.sales" value="false" checked> no
                                </td>...
1
  • also - the datepicker is working because i set the value = {{}} - I don't want to have to do that. shouldn't ng-model be enough? the radio isn't working no matter what Commented Feb 1, 2016 at 16:04

2 Answers 2

3

Use string

Since your'e using input type="radio", set the type of filter.sales to string, that should work

$scope.filter = {
    fromDate: '2015-05-01',
    toDate: '',
    sales: 'false'          
};

From input type="radio" ng-model docs,

The value to which the ngModel expression should be set when selected. Note that value only supports string values, i.e. the scope model needs to be a string, too. Use ngValue if you need complex models (number, object, ...).

Sign up to request clarification or add additional context in comments.

Comments

1

You can use ng-checked of angularjs for prefilling the radio button based on some other value.

for example:

<td width="40%">                                    
  <input type="radio" name="sales" ng-model=vm.filter.sales > yes
  <input type="radio" name="sales" ng-model=vm.filter.sales ng-checked="true"> no
</td>

In the above example I have directly set the ng-checked value to true but you can also set it to true or false using the controller variable also. For more information you can check the documentation @ https://docs.angularjs.org/api/ng/directive/ngChecked

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.