如何使用指令在Angular中加载外部模板?

时间:2014-11-06 05:48:11

标签: javascript angularjs angularjs-directive

如何使用指令在Angular中加载外部模板?

角,

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

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

HTML,

             

夹具/ m​​ain.html中,

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

什么都没有加载。知道我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

使用此

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

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

和HTML

<div ng-controller="SimpleController"><div hello-world></div></div>