Trying to replace spaces with dashes using ng-model

后端 未结 3 738
攒了一身酷
攒了一身酷 2021-01-11 13:53

I\'m new to AngularJS and trying to create a simple app that will allow me to upload files to my Laravel driven website. I want the form to show me the preview of what the u

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-11 14:14

    First, you have to inject your filter in you module by adding it's name to the array :

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

    Secondly, the function of the filter have to return something. The String.prototype.replace() return a new String. so you have to return it :

    app.filter('spaceless',function(){
        return function(input){
            return input.replace(' ','-');
        }
    });
    

    Edit: dfsq's answer being a lot more accurate than mine.

提交回复
热议问题