Dropdown value is not the new but the old one

UI Components for Angular
Post Reply
zamrokk
Posts: 6
Joined: 17 Mar 2016, 19:51

18 Mar 2016, 16:08

I use this code :

Code: Select all

 <p-dropdown [options]="predictionModels" [(value)]="selectedPredictionModel" (onChange)="recalculatePredictions()"></p-dropdown>
When I click on the dropdown to select un item 'B', then on my controller the value of 'this.selectedPredictionModel' is the old one 'A'.
Then the binding is correctly set by Angular after my function recalculatePredictions() returns.
If I click again, I see that is again the old value 'B' now, etc ...

Do I do it bad ? Is a solution passing arguments directly to get the new value on my controller ?

--------- DOCUMENTATION

Name

onChange

Parameters

event.originalEvent: Browser event
event.value: Single value or an array of values that are selected

Description

Callback to invoke when value of dropdown changes.

------------------


ALSO : After binding, this.selectedPredictionModel is equal to 'value' field of SelectItem and not the SelectItem himself. Is is normal ?

zamrokk
Posts: 6
Joined: 17 Mar 2016, 19:51

18 Mar 2016, 16:24

is the content of the binding when I enter the function on onChange. "DEFAULT" is the old value, it should be now "QEWS"

<p-dropdown #dropdownBinding ... (onChange)="recalculatePredictions(dropdownBinding) ...

Image

cagatay.civici
Prime
Posts: 18478
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

18 Mar 2016, 16:51

@Trypticon, please provide assistance.

User avatar
DarthMaul
Posts: 583
Joined: 23 Nov 2015, 21:20

19 Mar 2016, 13:38

I will look into that and get back to you immediately.

cagatay.civici
Prime
Posts: 18478
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

20 Mar 2016, 22:01

Can you please post sample code that we can try locally, especially we need, recalculatePredictions(), predictionModels and the selectedPredictionModel.

zamrokk
Posts: 6
Joined: 17 Mar 2016, 19:51

22 Mar 2016, 18:54

HTML :

Code: Select all

<p-dropdown [options]="predictionModels"
                                                        [(value)]="selectedPredictionModel"
                                                        (onChange)="recalculatePredictions()"></p-dropdown>
CONTROLLER :

Code: Select all

 //selections
    public predictionModels:Array<SelectItem>;
    public selectedPredictionModel:string;
    
...
  constructor(private _service:DeviceService, private _notification:NotificationsService) {
        this.predictionModels = [{label: "Self Discovery | V1.0 | DefaultSupplier", value: "SELF DISCOVERY"}, {label: "QEWS | V1.3 | Supplier1", value: "QEWS"}];
        this.selectedPredictionModel = this.predictionModels[0].value;}

...
public recalculatePredictions() {

        for (var i = 0; i < this.devices.length; i++) {
            var device = this.devices[i];
            switch (this.selectedPredictionModel) {
                case 'QEWS' :
                    this._service.calculateQEWS(device);
                    break;
                default :
                    this._service.calculateAt5PercentMore(device);
            }
        }

    }

cagatay.civici
Prime
Posts: 18478
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

22 Mar 2016, 21:59

Thank you, we're investigating.

zamrokk
Posts: 6
Joined: 17 Mar 2016, 19:51

23 Mar 2016, 11:26

optimus.prime wrote:Thank you, we're investigating.
I think is coming from Angular2 , see here : http://stackoverflow.com/questions/3370 ... -angular-2


This works now, not using PrimeNg :

Code: Select all

<form>
                                            <select [ngModel]="selectedPredictionModel" (ngModelChange)="recalculatePredictions($event)">
                                                <option *ngFor="#predictionModel of predictionModels" [attr.label]="predictionModel.label" [value]="predictionModel.value"></option>
                                            </select>
                                            </form>

Code: Select all

 public recalculatePredictions(newPredictionModel) {

        this.selectedPredictionModel=newPredictionModel;
        console.log(newPredictionModel);
...

cagatay.civici
Prime
Posts: 18478
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

23 Mar 2016, 16:00

Dropdown is being reimplement now as a native component for next week, I'll test this along the way to make sure it works well.

cagatay.civici
Prime
Posts: 18478
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

29 Mar 2016, 17:38

Dropdown is reimplemented as a native component for next week's 1.0.0-beta1 release and this issue is fixed.

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 7 guests