简体   繁体   中英

How to use directive to load an external template in Angular?

How can I use directive to load an external template in Angular?

Angular,

app.directive('helloWorld', function() {
    return {
        restrict: 'AE',
        replace: true,

        //templateUrl points to an external html template.
        emplateUrl: 'fixture/main.html'
    };
});

html,

fixture/main.html,

<div ng-controller="SimpleController">{{sayHello()}}</div>

Nothing is loaded. Any idea what have I missed?

Use this

app.directive('helloWorld', function() {
    return {
        restrict: 'AE',
        replace: true,

        //templateUrl points to an external html template.
        templateUrl: 'fixture/main.html'
    };
});

and in HTML

<div ng-controller="SimpleController"><div hello-world></div></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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM