user2919261 user2919261 - 1 month ago 7x
AngularJS Question

dynamic load function for ng-click with evel

You will find plunder of this here : plunker

UI is like this :

I have ng-repeat with which I want to create ng-click in directive template.
Template name as mainTemplate.html and its code is below code:

<form class="class">
<p>Inside directive</p>

<div ng-repeat='mainJson in mainJsonData'>
<div class="{{mainJson.divClass}}">
<input ng-model="mainJson[mainJson.inputNgModel]" type="{{mainJson.inputType}}" class="{{mainJson.inputClass}}" placeholder="{{mainJson.placeHolder}}" maxlength='{{mainJson.inputMaxLength}}' value="{{mainJson.value}}" ng-click="mainJson[mainJson.ngClick]()"/>


add.directive('testData', function() {
return {
templateUrl: 'template/mainTemplate.html',
controller: function($scope, $http) {
$http.get('json/mainUi.json').success(function(response) {
$scope.mainJsonData = response;

And json is with which i am trying to create directive :

"inputClass":"btn btn-success",
"ngClickData":"name, city, mobile"

and I am looking for ng-click as :

ng-click="addData(name, city, mobile)

which should work with ng-model as ng-model also get created same from


You can split the string in a array.

Like the example:

I put hard coded what you have, insted the name|city|mobile your is mainJson[mainJson.inputNgModel].


Its works, but idk if its good do what you are doing, the maintence will be very dificulty.

The working version based on yours: