I'd like to write own directive which can wrap any html element in 
hyperlink using the passed parameter, so for example:

    <button myDirective="parameter">...</button>


will have following effect

    <a href="url/parameter"><button>...</button></a>


I'm beginner in AngularJS. Unfortunately I didn't find any helpful tutorial 
for making this in **typescript**.

I created sth like that:

    export default class LinksHelperDirective implements ng.IDirective {
    public static Name = "kb-link";
    public restrict = "A";
    public urlTemplate = "";


    constructor(private readonly $parse: ng.IParseService) {
    }


    public static Factory() : any {
        const directive = ($parse: ng.IParseService) => {
            return new LinksHelperDirective($parse);
        };


        directive["$inject"] = ["$parse"];
        return directive;
    }


    link = (scope: ng.IScope, element: ng.IAugmentedJQuery, attrs: ng.
IAttributes,
        ngModel: ng.INgModelController) => {
        const linkId = this.$parse(attrs["kb-link"])(scope);
        const wrapper = angular.element('<a href="https://support/' + 
linkId + '"></a>');
        element.wrap(wrapper);
    };
}


But unfortunately it doesn't work... even constructor is not called. I 
registered directive in index file like below:

    
module.directive(LinksHelperDirective.Name, LinksHelperDirective.Factory(), 
["$parse"]);


and in html file:

   
 <button kb-link="1234">Help</button>


Anybody knows what's wrong with that?

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to