I have a directive that uses this template:
template: '<div id={{day}} ng-class="daystatus" ng-click="toggle()">{{day | date: "d"}}</div>'
the variable date contains a day which when executed renders as follows:
<div id=""2015-09-21T22:00:00.000Z"" ng-class="daystatus" ng-click="toggle()" class="ng-binding selectable" role="button" tabindex="0">22</div>
Question one: "Why is is placing the double quotes in the string in the first expression?
Question two: As you can see, in this case everything works as expected, but if I try to apply in the first expression to get the same formating as in the second one as such as:
template: '<div id={{day | date: "d"}} ng-class="daystatus" ng-click="toggle()">{{day | date: "d"}}</div>'
it simply does not render as expected producing the following HTML code:
<div id="{{day" |="" date:"d"}}="" ng-class="daystatus" ng-click="toggle()" class="ng-binding selectable" role="button" tabindex="0">22</div>
Any clue on why it is behaving like this?
You must escape the quotes in the attribute:
{
template: '<div id={{day | date: "d"}} ng-class="daystatus" ng-click="toggle()">{{day | date: "d"}}</div>'
}
To:
{
template: '<div id="{{day | date: \'d\'}}" ng-class="daystatus" ng-click="toggle()">{{day | date: "d"}}</div>'
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.