angularjs extends指令Configuration - 指令未定义

时间:2014-12-10 11:35:11

标签: angularjs angularjs-directive

我正在阅读令人惊叹的维基教程 https://github.com/angular/angular.js/wiki/Understanding-Directives#specialized-the-directive-configuration

我尝试过像

var app = angular.module('myApp', []);
app.controller('MainController',function() {

});
app.directive('one', function() {
    return {
            template: '<div>I am one</div>',
            controller:function(){

            },
            link:function($scope){

            }
        };
    });
app.directive('two', function() {
        return angular.extend({}, oneDirective[0], { template: '<div>I am two</div>' });     
});

但我有ReferenceError:oneDirective未定义

那怎么回事,拜托?

1 个答案:

答案 0 :(得分:0)

您忘了将第一个指令注入第二个指令:

app.directive('two', function(oneDirective) {
    return angular.extend({}, oneDirective[0], { template: '<div>I am two</div>' });     
});