【问题标题】:Can't use $mdSelect in angularjs directive不能在 angularjs 指令中使用 $mdSelect
【发布时间】:2018-05-18 14:03:39
【问题描述】:

我一直在研究一种在关闭 md 菜单时关闭 md-select 的方法。我已经弄清楚了 > https://codepen.io/anon/pen/jxXbrX.

但现在我试图在我自己的应用程序中实现它,但我在浏览器控制台中收到$mdSelect.hide is not a function 消息。

这是指令:

namespace Xxx{
    angular.module('Xxx')
    .directive('mdCloseSelect', ['$mdSelect', ($mdSelect) => {
        return {
            link (scope, element, attrs, $mdSelect) {
                scope.$on('$mdMenuClose', (ev, element, $mdSelect) => {

                    $mdSelect.hide();

                });
            }
        };
    }]);
}

我认为问题在于$mdSelect 的声明,但我找不到如何正确声明它。

【问题讨论】:

    标签: angularjs material-design


    【解决方案1】:

    这至少应该解决未定义的问题:

    angular.module('Xxx')
    .directive('mdCloseSelect', ['$mdSelect', ($mdSelect) => {
        return {
            link (scope, element, attrs) { // You can not inject here anything, this is always predefined 3 args
                scope.$on('$mdMenuClose', () => { // Here you also can not
    
                    $mdSelect.hide();
    
                });
            }
        };
    }]);
    

    附:使用一些 checkstyle ike Eslint,它会告诉你使用相同的变量名称是不好的。

    【讨论】:

    • 只是同时想到了这个:)
    猜你喜欢
    • 1970-01-01
    • 2016-10-27
    • 1970-01-01
    • 2015-07-30
    • 1970-01-01
    • 1970-01-01
    • 2018-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多