I have an input string containing element's name (I mean the "name" attribute). How to search $scope for element with given name?
What I want to do is to make a parametrized directive
<select bindslave="shipping_state" name="billing_state" ng-model="order.billing_state" ng-options="i.name for i in billingRegions" value="{{ order.billing_state.id }}"></select>
<select name="shipping_state" ng-model="order.shipping_state" ng-options="i.name for i in shippingRegions" value="{{ order.shipping_state.id }}"></select>
Currently the code in CoffeeScript looks like this:
app_directives.directive "bindslave", ->
require: "ngModel"
link: (scope, element, attrs, ctrl) ->
ctrl.$parsers.unshift (viewValue) ->
if scope.sameAsBilling
switch attrs['bindslave']
when "shipping_state"
scope.order.shipping_state = viewValue
when "shipping_country"
scope.order.shipping_country = viewValue
viewValue
I want to get rid of switch statement and search for an element with name==attrs['bindslave']