1

Angular 1.4 から angular 1.5 コンポーネントに移行してから typescript に移行しようとしています:

Angular 1.5 コンポーネントを使用したいのですが、彼女は私のコードであり、不完全ですが、これはアイデアです。

angular.
module('cool.core').
component('hasAnyRole', {
    template: 'Hello, {{$ctrl.user}}!',
    controller: function GreetUserController() {
        this.user = 'world';
    }
})

Angular-directive-link の代わりに:

angular.module('cool.core')
    .directive('hasAnyRole', ['Principal', function (Principal) {
        return {
            restrict: 'A',
            link: function (scope, element, attrs) {
                var roles = attrs.hasAnyRole.replace(/\s+/g, '').split(',');

                var setVisible = function () {
                    element.removeClass('hidden');
                };
                var setHidden = function () {
                    element.addClass('hidden');
                };

                var defineVisibility = function (reset) {
                    var result;
                    if (reset) {
                        setVisible();
                    }

                    result = Principal.isInAnyRole(roles);
                    if (result) {
                        setVisible();
                    } else {
                        setHidden();
                    }
                };

                if (roles.length > 0) {
                    defineVisibility(true);
                }
            }
        };
    }])

ただし、十分な例が見つかりません。ご提案いただきありがとうございます。

4

0 に答える 0