Javascript 如何将参数传递给角度指令内的函数?

Javascript 如何将参数传递给角度指令内的函数?,javascript,angularjs,angularjs-directive,scope,Javascript,Angularjs,Angularjs Directive,Scope,在中,我触发一个回调函数,该函数需要访问已注入的指令级对象 我正在为此使用一个KendoUI模板函数,但是我认为这更多的是关于范围的问题,而不是函数的问题 指令: app.directive('projectEditorGrid', function (dataSourceFactory) { var dataSourceFactory = new dataSourceFactory("/odata/ProjectEditor"); return { link

在中,我触发一个回调函数,该函数需要访问已注入的指令级对象

我正在为此使用一个KendoUI模板函数,但是我认为这更多的是关于范围的问题,而不是函数的问题

指令:

app.directive('projectEditorGrid', function (dataSourceFactory) {

    var dataSourceFactory = new dataSourceFactory("/odata/ProjectEditor");

    return {
        link: function ($scope, $element, $attrs) {
            $element.kendoGrid({
                dataSource: dataSourceFactory.projects(),
                pageable: true,
                height: 400,
                toolbar: ["create"],
                columns: [
                            { field: "WebsiteName", editable: true, width: 190, title: "Project Name", validation: { required: { message: "Project name is required" } } },
                            { field: "WebsiteNotes", title: "Project Notes" },
                            { field: "WebsiteGUID", title: "Project API ID", editable: false },
                            { field: "DefaultContentType", title: "Default Content Type", width: "160px", editor: defaultContentTypeDropDownEditor, template: "#=ContentTypes.Descriptions#" },
                            { command: ["edit", "destroy"] }
                ],
                editable: "inline"
            });

            function defaultContentTypeDropDownEditor(container, options) {
                console.log(container + " : " + options);
                var dataSourcFactory = dataSourceFactory("/odata/ContentType");
                var dsContentTypes = dataSourceFactory.contentTypes();  // returns a kendo.data.DataSource() object

                $('<input required data-text-field="Description" data-value-field="ContentTypeId" data-bind="value:' + options.field + '"/>')
                    .appendTo(container)
                    .kendoDropDownList({
                        autoBind: false,
                        dataSource: dataSourceFactory.contentTypes()
                    }); // kendoDropDownList
            }
        }
    }
});
容器

[<td role=​"gridcell" data-container-for=​"DefaultContentType">​</td>​]
[​​]

如您所见,
dataSourceFactory
在函数级别可见(注入到指令中)但是,无法从
defaultContentTypeDropDownEditor
中访问。是否有人可以解释如何完成此操作?

注入的对象是
dataSourceFactory
。方法是将初始初始化重命名为
dataSourceFactory1
,并将函数回调的用法重命名为
dataSourceFactory2
,我能让它工作


感谢Nikos为我指明了正确的方向。

您有一个
var DataSourceFactory
(缺少
e
)。这是一个输入错误吗?如果是,并且var的实际名称是
dataSourceFactory
,它会从外部范围隐藏
dataSourceFactory
。请尝试将其重命名为有意义但不同的名称。您的注释命名和隐藏范围将引导我找到答案,谢谢。
[<td role=​"gridcell" data-container-for=​"DefaultContentType">​</td>​]