Reputation: 41
This is probably stupid simple, but I can't figure it out.
I am building a string in javascript
var template = '<div class="big-long-string-here">';
Now that works fine, but say I wanted to use ng-class
with this div.
var template = '<div class="big-long-string-here" ng-class="{'open' : navCollapsed}">
Now, I'm escaping the string to place my class name, open in the string.
How would I pass this properly so it's rendered correctly in the DOM?
Upvotes: 2
Views: 1855
Reputation: 517
$templateCache.put('udt-toolbar.html', '<div ng-class="{{datatable.config.name ? \'your-class\' : \' \'}}" name="udt-toolbar" class="button-toolbar-main clearfix"></div>');
This is how can be resolved.
Upvotes: 0
Reputation: 1
You can use template literal
var template = `<div class="big-long-string-here" ng-class='{"open" : "navCollapsed"}'>`;
If navCollapsed
is a variable identifier
var template = `<div class="big-long-string-here" ng-class='{"open" : ${navCollapsed}}'>`;
Upvotes: 0
Reputation: 781750
Use string concatenation.
var template = '<div class="big-long-string-here" ng-class="{' + open + ' : navCollapsed}">
Upvotes: 2