If you are meaning you want to have a catch-all where all the attributes prefixed with say my (as you should use your own prefix) get evaluated and then set to their respective non-prefixed attribute you will need to:
- Make your own custom directive
- Find all attributes on the element (provided by $attrs)
- Get the evaluated value
- Set the actual attribute on the element
I won't cover making the actual directive you can find out that here
In the link function of your directive one of the arguments will be $attrs. $attrscontains the normalized(camel cased) and non-normalized attribute names, their respective evaluated values(if using expressions), and some helper methods.
So you can simply loop over the $attrs (or $attrs.$attr) keys, filtering out ones you shouldn't be using like ng-model, ng-selected, etc, get the evaluated value and then set the respective non-prefixed counterpart.
Object.keys($attrs).filter(function(key){ //filter out keys like ngModel,ngSelect,$set etc return /^my/.test(key); }).forEach(function(key){ //$attrs.$attr contains the non-normalized //versions of the attributes //this example assumes you will prefix with `my` //so remove `my-` to get the attribute name to set var attrName = $attrs.$attr[key].replace("my-",""); //Use $parse() if you just want to use some scope's property name //for example my-attribute="somePropertyName" $attrs.$set(attrName,$parse($attrs[key])($scope)); //Use just $attrs[key] if you are using some expression //for example my-attribute="{{somePropertyName}}" $attrs.$set(attrName,$attrs[key]); });
angular.module("test",[]) .controller("ctrl",function($scope){ $scope.someprop = "Some Value"; }) .directive("caAttr",function($parse){ return { restrict : 'A', link : function($scope, $element, $attrs) { console.log($attrs); Object.keys($attrs).filter(function(key){ return /^my/.test(key); }).forEach(function(key){ var attrName = $attrs.$attr[key].replace("my-",""); $attrs.$set(attrName,$parse($attrs[key])($scope)); }); angular.element("#log").text( angular.element("#container").html() ); } }; });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="test" ng-controller="ctrl"> <div id="container"> <div ng-model="mymodel" ng-selected="{{nothing}}" my-stack="someprop" ca-attr></div> </div> <div id="log"></div> </div>
ng-unless the core directive actually exists