Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular service that converts camel case strings to hyphenated

I understand that Angular converts directive names from camel case to hyphen separated strings.

Is this functionality accessible through the API, like a function or something? I would like to convert some strings to hyphenated versions in my angular app and I don't want to reinvent the wheel if not necessary.

like image 561
Midiparse Avatar asked Jan 25 '15 10:01

Midiparse


2 Answers

The function used can be found here

Unfortunately, it is not available through API.

lodash has method kebabCase that does exactly this.

like image 197
Stas Avatar answered Nov 16 '22 19:11

Stas


I used the below code to convert the Camelcase string into directive name format.

myApp.filter(`con2directivename`,function(){
   return function(name){
        return name.replace(/([A-Z])/g, function($1){return "-"+$1.toLowerCase();});
    };
});
like image 2
Balamurugan Avatar answered Nov 16 '22 19:11

Balamurugan