Let me explain a straightforward directive:
<div my-directive>
<span ng-click="reveal()">Click Me</span>
<!-- More content goes here -->
</div>
Whenever I click on Click Me
, it triggers a modal that displays a form for editing some information. All the details in this form are part of the scope.form
data. Let's assume there is only one element named name
within this object.
This is how I implemented it in my directive:
scope.reveal = function()
{
var el = $compile('<input type="text" ng-model="scope.form.name" />')(scope);
// Modal initialization code
}
The modal pops up successfully with the correct value of
scope.form.name</code. However, upon closing and reopening the modal, the value isn't retained (meaning, the <code>scope.form.name
remains unaltered within the directive).
What would be the most effective way to address this issue?