question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular parser strips single quotes from ngClass

See original GitHub issue

Prettier 1.15.3 Playground link

--parser angular

Input:

<div [ngClass]="{ 'x': y }"></div>

Output:

<div [ngClass]="{ x: y }"></div>

Expected behavior: The single quotations around the x should not be stripped out.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
artemzakharovcommented, Jan 19, 2019

@duailibe No, I am not worried that it will break the app - I am worried that it will lead to what some (including myself) would consider inconsistent styling, where someone who isn’t familiar with the otherwise somewhat obscure rules regarding multiple, dash separated word variable names in JS would be confused at why some ngClass examples get stripped of quotes, and others don’t. This is further amplified by the fact that while the parser strips quotes when they aren’t needed, it doesn’t add them where they are needed, creating further confusion for someone who might modify a single word class into a multi word one, and suddenly run into a compilation error.

At the end of the day, I’m just worried that newbies are going to get confused, but its possible that I’m worrying too much, so it would help if any other Angular devs could give their thoughts.

1reaction
creadictedcommented, Jan 17, 2019

Whitespace around will not lead to the removal of the quotes. [ngClass]="{ 'active': isActive }"> here the quotes will be removed [ngClass]="{ ' active ': isActive }"> here not

Read more comments on GitHub >

github_iconTop Results From Across the Web

VS Code Prettier extension replaces single quotation marks to ...
angular - VS Code Prettier extension replaces single quotation marks to double and removes backslash marks - Stack Overflow. Stack Overflow for ...
Read more >
ngClass - Unsaved project - Plunker
var app = angular.module('plunker', []); app.controller('MainCtrl', function($scope, $timeout) { $scope.like = true; $scope.button = true; $scope.cool ...
Read more >
Template Syntax - ts - GUIDE - Angular
A template statement responds to an event raised by a binding target such as an element, component, or directive. You'll see template statements...
Read more >
Angular with haml: Dynamic html classes - makandra dev
jQuery's removeClass removes the given class string from an element collection. If you want to remove multiple/unknown classes matching a given pattern, you...
Read more >
Template Syntax - dart - GUIDE - Angular
A template reference variable is one such alternative context object. ... The template statement parser is different than the template expression parser and ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found