toddmotto / ama

Ask me anything!
20 stars 3 forks source link

HTML in Angular #67

Closed ghost closed 7 years ago

ghost commented 7 years ago

When templating in Angular do you prefer to;

angular
        .module('app.directives')
        .directive('sideNav', [
            '$mdSidenav',
            function( $mdSidenav ) {
                return {
                    templateUrl: 'scripts/directives/sidenav/sidenav.html',
                    link: function(scope, element, attrs, ngModel) {
                        scope.lockLeft = true;

                    }
                }
            }
        ])

or

angular
        .module('app.directives')
        .directive('sideNav', [
            '$mdSidenav',
            function( $mdSidenav ) {
                return {
                    template: `
                        <aside>
                            <h2></h2>
                        </aside>
                    `,
                    link: function(scope, element, attrs, ngModel) {
                        scope.lockLeft = true;

                    }
                }
            }
        ])

Personally I've always preferred to use templateUrl because it adds to cleaner code output.

Would like your offerings

toddmotto commented 7 years ago

Personally I prefer template, demo here using components:

https://jsfiddle.net/toddmotto/kpvqf9gf/