{"id":429,"date":"2015-07-15T10:31:42","date_gmt":"2015-07-15T08:31:42","guid":{"rendered":"http:\/\/blog.thecodecampus.de\/?p=429"},"modified":"2023-12-20T19:56:47","modified_gmt":"2023-12-20T18:56:47","slug":"convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs","status":"publish","type":"post","link":"https:\/\/www.thecodecampus.de\/blog\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\/","title":{"rendered":"Convert Strings from hyphen-notation to camel case Part 2 (AngularJS)"},"content":{"rendered":"<p>In my last <a href=\"https:\/\/blog.thecodecampus.de\/convert-strings-from-hypen-notation-to-camel-case-java-guava\/\" target=\"_blank\" rel=\"noopener noreferrer\">post i demonstrated<\/a> how to convert Strings from Hyphen Format to CamelCase in Java, using the popular Framework <a href=\"https:\/\/code.google.com\/p\/guava-libraries\/wiki\/StringsExplained\" target=\"_blank\" rel=\"noopener noreferrer\">Guava<\/a> from Google.<\/p>\n<p>In AngularJS this can be achieved using a Regular Expression and an AngularJS <a href=\"https:\/\/docs.angularjs.org\/api\/ng\/filter\/filter\" target=\"_blank\" rel=\"noopener noreferrer\">Filter<\/a>.<\/p>\n<h3>1) Create a constant function which does the replacement<\/h3>\n<p>Our first step is to create a Regular expression which does the conversion from a camel Case Text to Hyphen Format. For reusing purpose we are storing this as a AngularJS constant.<\/p>\n<pre class=\"lang:js decode:true\">angular.module('common').constant('camelCaseToHyphens', function(str) {\r\n   return str.replace(\/([A-Z])\/g, function($1) { return '-' + angular.lowercase($1); });\r\n});\r\n<\/pre>\n<h3>2) Create an AngularJS Filter Function<\/h3>\n<p>The second step is to register the constant as a AngularJS Filter. The constant is injected from AngularJS<\/p>\n<pre class=\"lang:js decode:true\">angular.module('common').filter('camelCaseToHyphens', function(camelCaseToHyphens) {\r\n   return camelCaseToHyphens;\r\n});<\/pre>\n<h3>3) Usage in HTML<\/h3>\n<p>We can now use the filter in any Html element, as displayed in the next code snippet.<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;span&gt;\r\n  {{'camelCase' | camelCaseToHyphens}}\r\n&lt;\/span&gt;<\/pre>\n<p>The following <a href=\"https:\/\/jsfiddle.net\/jblankenhorn\/fcvqxjea\/\" target=\"_blank\" rel=\"noopener noreferrer\">fiddle<\/a> shows all the examples from this blog post!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my last post i demonstrated how to convert Strings from Hyphen Format to CamelCase in Java, using the popular Framework Guava from Google. In AngularJS this can be achieved using a Regular Expression and an AngularJS Filter. 1) Create a constant function which does the replacement Our first step is to create a Regular [&#8230;]<br \/><a class=\"meta-big\" href=\"https:\/\/www.thecodecampus.de\/blog\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\/\"> READ MORE<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,2],"tags":[62,61,83],"class_list":["post-429","post","type-post","status-publish","format-standard","hentry","category-angularjs","category-javascript","tag-angularjs","tag-javascript","tag-tooling"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Convert Strings from hyphen-notation to camel case Part 2 (AngularJS) - Web Development Blog<\/title>\n<meta name=\"description\" content=\"Unlock AngularJS magic! Convert hyphen notation to camel case effortlessly. Elevate string transformations. Optimize your coding journey\u2014try it now!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.thecodecampus.de\/blog\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Convert Strings from hyphen-notation to camel case Part 2 (AngularJS) - Web Development Blog\" \/>\n<meta property=\"og:description\" content=\"Unlock AngularJS magic! Convert hyphen notation to camel case effortlessly. Elevate string transformations. Optimize your coding journey\u2014try it now!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.thecodecampus.de\/blog\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Development tips and tricks - theCodeCampus Blog\" \/>\n<meta property=\"article:published_time\" content=\"2015-07-15T08:31:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-20T18:56:47+00:00\" \/>\n<meta name=\"author\" content=\"Jan Blankenhorn\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jan Blankenhorn\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\\\/\"},\"author\":{\"name\":\"Jan Blankenhorn\",\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/#\\\/schema\\\/person\\\/623acdcedf59e3d9d86df17721a46188\"},\"headline\":\"Convert Strings from hyphen-notation to camel case Part 2 (AngularJS)\",\"datePublished\":\"2015-07-15T08:31:42+00:00\",\"dateModified\":\"2023-12-20T18:56:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\\\/\"},\"wordCount\":141,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/#organization\"},\"keywords\":[\"AngularJS\",\"JavaScript\",\"Tooling\"],\"articleSection\":[\"AngularJS 1\",\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\\\/\",\"url\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\\\/\",\"name\":\"Convert Strings from hyphen-notation to camel case Part 2 (AngularJS) - Web Development Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/#website\"},\"datePublished\":\"2015-07-15T08:31:42+00:00\",\"dateModified\":\"2023-12-20T18:56:47+00:00\",\"description\":\"Unlock AngularJS magic! Convert hyphen notation to camel case effortlessly. Elevate string transformations. Optimize your coding journey\u2014try it now!\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Convert Strings from hyphen-notation to camel case Part 2 (AngularJS)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/\",\"name\":\"Web Development tips and tricks - theCodeCampus Blog\",\"description\":\"Tips, tricks, and experiences about developing web and mobile applications with Angular, TypeScript, and Testing.\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/#organization\",\"name\":\"theCodeCampus\",\"url\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/TCC-Logo-Bildmarke-quadratisch.jpg\",\"contentUrl\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/TCC-Logo-Bildmarke-quadratisch.jpg\",\"width\":156,\"height\":156,\"caption\":\"theCodeCampus\"},\"image\":{\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/#\\\/schema\\\/person\\\/623acdcedf59e3d9d86df17721a46188\",\"name\":\"Jan Blankenhorn\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/06\\\/jan-blankenhorn-tcc-author-96x96.webp\",\"url\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/06\\\/jan-blankenhorn-tcc-author-96x96.webp\",\"contentUrl\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/06\\\/jan-blankenhorn-tcc-author-96x96.webp\",\"caption\":\"Jan Blankenhorn\"},\"description\":\"Jan Blankenhorn brings over 15 years of experience as a developer and trainer, specializing in web development with Angular. He enjoys engaging with people and shares practical examples in his training sessions with a touch of humor.\",\"sameAs\":[\"https:\\\/\\\/thecodecampus.de\\\/ueber-uns\\\/trainer\\\/jan-blankenhorn\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/jan-blankenhorn-w11k\\\/\"],\"url\":\"https:\\\/\\\/www.thecodecampus.de\\\/blog\\\/author\\\/jblankenhorn\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Convert Strings from hyphen-notation to camel case Part 2 (AngularJS) - Web Development Blog","description":"Unlock AngularJS magic! Convert hyphen notation to camel case effortlessly. Elevate string transformations. Optimize your coding journey\u2014try it now!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.thecodecampus.de\/blog\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\/","og_locale":"en_US","og_type":"article","og_title":"Convert Strings from hyphen-notation to camel case Part 2 (AngularJS) - Web Development Blog","og_description":"Unlock AngularJS magic! Convert hyphen notation to camel case effortlessly. Elevate string transformations. Optimize your coding journey\u2014try it now!","og_url":"https:\/\/www.thecodecampus.de\/blog\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\/","og_site_name":"Web Development tips and tricks - theCodeCampus Blog","article_published_time":"2015-07-15T08:31:42+00:00","article_modified_time":"2023-12-20T18:56:47+00:00","author":"Jan Blankenhorn","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Jan Blankenhorn","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.thecodecampus.de\/blog\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\/#article","isPartOf":{"@id":"https:\/\/www.thecodecampus.de\/blog\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\/"},"author":{"name":"Jan Blankenhorn","@id":"https:\/\/www.thecodecampus.de\/blog\/#\/schema\/person\/623acdcedf59e3d9d86df17721a46188"},"headline":"Convert Strings from hyphen-notation to camel case Part 2 (AngularJS)","datePublished":"2015-07-15T08:31:42+00:00","dateModified":"2023-12-20T18:56:47+00:00","mainEntityOfPage":{"@id":"https:\/\/www.thecodecampus.de\/blog\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\/"},"wordCount":141,"commentCount":0,"publisher":{"@id":"https:\/\/www.thecodecampus.de\/blog\/#organization"},"keywords":["AngularJS","JavaScript","Tooling"],"articleSection":["AngularJS 1","JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.thecodecampus.de\/blog\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.thecodecampus.de\/blog\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\/","url":"https:\/\/www.thecodecampus.de\/blog\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\/","name":"Convert Strings from hyphen-notation to camel case Part 2 (AngularJS) - Web Development Blog","isPartOf":{"@id":"https:\/\/www.thecodecampus.de\/blog\/#website"},"datePublished":"2015-07-15T08:31:42+00:00","dateModified":"2023-12-20T18:56:47+00:00","description":"Unlock AngularJS magic! Convert hyphen notation to camel case effortlessly. Elevate string transformations. Optimize your coding journey\u2014try it now!","breadcrumb":{"@id":"https:\/\/www.thecodecampus.de\/blog\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.thecodecampus.de\/blog\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.thecodecampus.de\/blog\/convert-strings-from-hyphen-notation-to-camel-case-part-2-angularjs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.thecodecampus.de\/blog\/"},{"@type":"ListItem","position":2,"name":"Convert Strings from hyphen-notation to camel case Part 2 (AngularJS)"}]},{"@type":"WebSite","@id":"https:\/\/www.thecodecampus.de\/blog\/#website","url":"https:\/\/www.thecodecampus.de\/blog\/","name":"Web Development tips and tricks - theCodeCampus Blog","description":"Tips, tricks, and experiences about developing web and mobile applications with Angular, TypeScript, and Testing.","publisher":{"@id":"https:\/\/www.thecodecampus.de\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.thecodecampus.de\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.thecodecampus.de\/blog\/#organization","name":"theCodeCampus","url":"https:\/\/www.thecodecampus.de\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.thecodecampus.de\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.thecodecampus.de\/blog\/wp-content\/uploads\/2024\/01\/TCC-Logo-Bildmarke-quadratisch.jpg","contentUrl":"https:\/\/www.thecodecampus.de\/blog\/wp-content\/uploads\/2024\/01\/TCC-Logo-Bildmarke-quadratisch.jpg","width":156,"height":156,"caption":"theCodeCampus"},"image":{"@id":"https:\/\/www.thecodecampus.de\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.thecodecampus.de\/blog\/#\/schema\/person\/623acdcedf59e3d9d86df17721a46188","name":"Jan Blankenhorn","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.thecodecampus.de\/blog\/wp-content\/uploads\/2024\/06\/jan-blankenhorn-tcc-author-96x96.webp","url":"https:\/\/www.thecodecampus.de\/blog\/wp-content\/uploads\/2024\/06\/jan-blankenhorn-tcc-author-96x96.webp","contentUrl":"https:\/\/www.thecodecampus.de\/blog\/wp-content\/uploads\/2024\/06\/jan-blankenhorn-tcc-author-96x96.webp","caption":"Jan Blankenhorn"},"description":"Jan Blankenhorn brings over 15 years of experience as a developer and trainer, specializing in web development with Angular. He enjoys engaging with people and shares practical examples in his training sessions with a touch of humor.","sameAs":["https:\/\/thecodecampus.de\/ueber-uns\/trainer\/jan-blankenhorn","https:\/\/www.linkedin.com\/in\/jan-blankenhorn-w11k\/"],"url":"https:\/\/www.thecodecampus.de\/blog\/author\/jblankenhorn\/"}]}},"_links":{"self":[{"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/posts\/429","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/comments?post=429"}],"version-history":[{"count":3,"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/posts\/429\/revisions"}],"predecessor-version":[{"id":2182,"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/posts\/429\/revisions\/2182"}],"wp:attachment":[{"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/media?parent=429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/categories?post=429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thecodecampus.de\/blog\/wp-json\/wp\/v2\/tags?post=429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}