javascript - How to create new tag element in Angular.js -


i want create new element in angular.js

<link url="http://google.com">google</link> 

that converted <a> tag, how can this?

the code far:

var app = angular.module('app', []); app.directive('link', function() {     return {         restrict: 'e',         transclude: true,         replace: true,         scope: false,         template: '<a href="" ng-transclude></a>';     } }); 

but render google after link , don't know how url.

you can in linking function. directive this:

app.directive('link', function() {     return {         restrict: 'e',         transclude: true,         replace: true,         scope: false,         template: '<a href="{{url}}" ng-transclude></a>',         link: function(scope, element, attrs) {             scope.url = attrs.url;         }     } }); 

if you're ok creating isolated scope directive, can this:

app.directive('link', function() {     return {         restrict: 'e',         transclude: true,         replace: true,         scope: {             url: '@'         },         template: '<a href="{{url}}" ng-transclude></a>'     } }); 

then url attribute automatically put scope of directive.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -