I have set up my isolated directive to receive a string using the @
scope configuration. My goal is to convert this string into an object on the scope, so that I can manipulate its properties and values.
Here's how it looks in HTML:
<div directive model="object.property.property"></div>
And here's the corresponding JavaScript code:
directive('directive', function($parse) {
scope: {
model: '@'
},
link: function (scope, elem, attrs) {
var object = $parse(scope.model);
object(scope);
scope.object.property.property = 'newstring';
// scope.object.property.property = 'newstring';
}
});
I expected this implementation to assign the value of 'newstring' to object.property.property
on the scope.
However, it seems like my usage of the $parse
service may be incorrect. Most examples I come across are focused on converting JSON data. How can I correctly utilize $parse
to transform this string into an object within the directive's scope?
Thank you for any help!