0

Assuming I have this demo directive:

app.directive('name', function(){
    return{
        restrict: 'E',
        template: '<div ng-class="done" ng-click="doSomething(data.done, index)">{{data.text}}<button ng-click="remove(index)">delete</button></div>'  
    }
});

Is it ok just to break the string for the template, or should I add "+" or something in the end of each line? e.g. -

app.directive('name', function(){
    return{
        restrict: 'E',
        template: '<div ng-class="done" ng-click="doSomething(data.done, index)">
                       {{data.text}}
                       <button ng-click="remove(index)">delete</button>
                   </div>'
    }
});

Thank you :)

2
  • have you considered using templateUrl and putting your html inside of an .html file? Commented Jan 21, 2015 at 2:34
  • Well it's really simple in my case, so no. Just thought about this scenario in general :) Commented Jan 21, 2015 at 2:52

1 Answer 1

2

You can't break lines in single quotes without getting an error. You can use double quotes, but that's not recommended in strict JavaScript mode. Probably best to use one string per line with a + at the end, creating the result

Notes on double quotes: line breaks using javascript strings

It's probably better to use a templateUrl if the template is going to get more complicated.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.