0

I have generated a dynamic form HTML using angular js directive and I want to assign values to the generated textbox using the values I provided (values may come from database or from array)

when I am not sending any parameter dynamically, its normally run by following code and assign value to the textbox

 $scope.submitted = function() {
    $scope.title = "submitted";
  };

But when I am sending dynamic value to the form then Its not working.

The function got called from the directive after click and showing alert from that function but the value not assigning to the textbox by model. Here is the code

$scope.submitted = function(par) {
    alert(par); 
    $scope.title = par;
  };

Please findout the code on following plunker:

http://plnkr.co/edit/hcM7DX46fDl68axs2ol2?p=preview

1 Answer 1

2

The problem is that each dynamic directive is compiled in isolated child scope. So when you later set outer scope property title it does not affect local directives scope.

What you can do is inside of $scope.submitted function set ngRepeat child scope title and pass this value to directive with scope config object:

$scope.submitted = function(par) {
    this.title = par; // this points to individual ngRepeate scope object
};

and in directive configuration:

scope: {
    title: '=model',
    param1: '@',
    formFn: '&'
},

and use directive like this

<div dynamic param1="{{lang}}" form-fn="submitted(lang)" model="title"></div>

Demo: http://plnkr.co/edit/Nb2yh0wlGEyuOqQN8YS3?p=preview

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.