ng-options how to set first select always blank

前端 未结 8 2095
耶瑟儿~
耶瑟儿~ 2020-12-05 12:44

I am using angularjs in a project and in which I am using ng-options for generating .

Initially when the pages reload and no option element is selected the html gene

8条回答
  •  攒了一身酷
    2020-12-05 13:06

    The solution above will corrupt the model with junk data. Please use the directive to reset the model in the right way JS: Select Option

    Directive"
     .directive('dropDown', function($filter) {
        return {
    
            require: 'ngModel',
            priority: 100,
            link: function(scope, element, attr, ngModel) {
    
                function parse(value) {
    
                    if (value) {
    
                        if(value === "")
                        {
                            return "crap"
                        }
                        else
                        {
                            return value;
                        }
    
                    } else {
                        return;
                    }
                }
    
    
                ngModel.$parsers.push(parse);
    
            }
        };
    });
    

提交回复
热议问题