3

I have this select dropdown with "Enbridge Billing" selected.

<select class="form-control required ng-pristine ng-valid" ng-model="finance.payment_method" id="payment_method" name="payment_method">
    <option value=""></option>
    <option value="EGD" selected="selected">Enbridge Billing</option>
    <option value="PAPP">PAD Billing</option>
</select>

However, on screen, it's not selected:

Empty Select dropdown

I've removed all the stuff from app.js and still the problem presists:

var app = angular.module('portal', []);

app.config(function($interpolateProvider) {
    $interpolateProvider.startSymbol('%%');
    $interpolateProvider.endSymbol('%%');
});

app.controller('NewJobFinanceController',
    function ($scope) {


    });

Edit:

I just did this in the controller:

$scope.finance.payment_method = $('#payment_method').find(':selected').val();
1

2 Answers 2

4

The single point of truth in angular is the model. Not the view. You update the model, and the view updates itself to reflect the state of the model.

You configured the select box as

<select ng-model="finance.payment_method" ...>

So that means that the currently selected value is finance.payment_method. That's where angular gets the selected value. Since it's undefined, you have a blank select box.

BTW, you should not set, required, ng-pristine and ng-valid as class of your select box. angular will add and remove this classes by itself, depending on the actual state of the form control.

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

Comments

2

Simply use ng-selected="true" instead of selected="selected".

3 Comments

Hey, I ran this jQuery command but it doesn't work. $('[selected="selected"]').attr('ng-selected', 'true')
This is not a jquery command. Use it in this way: <option ng-selected="true">Value2</option> ie: directly into the html.
Thank you, I just did this: $scope.finance.payment_method = $('#payment_method').find(':selected').val();

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.