Why does my JavaScript constructor return default property value instead of the modified one?

前端 未结 1 681
死守一世寂寞
死守一世寂寞 2021-01-28 14:50

I am working on a small AngularJS application with with Material Steppers.

I have to select items from two sections of the page and return true only if<

1条回答
  •  清酒与你
    2021-01-28 15:09

    At the top of your application you are declaring:

        this.isTriggerA = true;
        this.isTriggerB = true;
    

    That means that the default value for both is true, so if both your if conditions:

    if (parseInt(this.clickedStepNumber, 10) === 1) 
    

    And

    if (parseInt(this.clickedStepNumber, 10) === 2)
    

    Are false, the last statement this.isTriggerA === true && this.isTriggerB === true will always be true.

    To do not execute this by default, set isTriggerA and isTriggerB to false at the beginning of your code

    Since your condition is:

    I have to select items from two sections of the page and return true only if the items from both sections belong to the category with id (categoryID) 1.

    There is no sense in to keeping those 2 values as true by default

    0 讨论(0)
提交回复
热议问题