【问题标题】:angularjs extends directive Configuration - directive is not definedangularjs 扩展指令配置 - 指令未定义
【发布时间】:2014-12-10 20:44:07
【问题描述】:

我正在阅读精彩的 wiki 教程 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 is not defined

请问有什么事吗?

【问题讨论】:

  • oneDirective 没有在任何地方定义。

标签: angularjs angularjs-directive


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2013-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-25
    • 2016-01-08
    • 1970-01-01
    • 2014-06-24
    • 2015-06-21
    相关资源
    最近更新 更多