I have directive 'copyPaste' which copies element value to the element specified in 'destination' attribute.
// html code
<div ng-app='app'>
<div ng-controller="mainController">
<input type='text' ng-model='firstInput' copy-paste destination='secondInput'>
<input type='text' ng-model='secondInput'>
<!-- following does not work -->
<input type='text' ng-model='param.firstInput' copy-paste destination='param.secondInput'>
<input type='text' ng-model='param.secondInput'>
</div>
</div>
//directive code
module.directive('copyPaste',['$rootScope',function($rootScope){
return {
restrict:'A',
link:function(scope,element,attrs,ctrl){
var destination=attrs.destination;
scope.$watch(attrs.ngModel, function (v) {
scope[destination]=v
});
}
}
}])
//controller
module.controller('mainController',['$scope',function($scope){
$scope.firstInput='hello'
}]);
Above code works if I pass simple variable. If I pass object , array it does not work . How can I pass array and objects to directive as string then use as variables. I dont want to run directive in isolate scope, in isolate scope I need to call $scope.$apply to update binding so trying to avoid isolate scope.