I am new to angular. I want to write a directive that has all the attributes that I added to it when used in html. For instance:
This is my directive.
'use strict'; app.directive('province', function($compile) { return { restrict: 'E', link: function (scope, element, attrs, controller) { var markup = "<select></select>"; var elem = angular.element(element); elem.replaceWith($compile(markup)(scope)); } }; })
HTML:
<province class="form-control" data-target"elemntId"></province>
I want my <select> contain the class and other attributes that I added to the directive in html.
which I want: <select class="form-control" data-target="elementId"></select>
I used angular.element(element).attr(attr); but it did not work;
Any help is appreciated in advance.
Edit
I want all the attributes that exist in the attrs link function to be added to markup .
source share