Set default value in select when the ng-model is null

前端 未结 8 2142
悲哀的现实
悲哀的现实 2021-02-05 10:33

I\'m new to angular and i\'m trying to set a default state to select when my ng-model is null. Basically I want to set it to \'None\' if the model is empty. I tried the below co

8条回答
  •  独厮守ぢ
    2021-02-05 11:07

    Based on Rob Sedgwick idea, in a pinch deadline I'm not using $scope so with controller as syntax.

    loadStates(); //this calls my function for my code
    
    // this is based on what Rob S. is doing with $scope    
    if(typeof vm.scriptQuestion.statecode ==="undefined") {
        console.log('in');
        vm.scriptQuestion.statecode = "AA";  // "AA" happens to be the value of the default name for All of my States that is then displaying "ALL" now when before it was blank
    }
    

    Here is my Select ( yes, this is a garbage way of doing angular select boxes as ng-repeat is very limited for a select )

     
    

提交回复
热议问题