I'm trying to create a directive to cut down on the boilerplate code that I'd have to write.
I'm using the angular xeditable directive to allow for inline editing, but when I add the xeditable directive attributes from my directive, it doesn't work.
When I say it doesn't work, I mean usually when I click on the element there is an input box that appears, and right now nothing happens when I click on the element.
Glenn.directive('edit', function() {
return {
restrict: 'A',
template: '{{ content.' + 'ParamData' + '.data }}',
scope: {
ParamData: '@edit'
},
link: function(scope, element, attrs) {
element.attr('editable-text', 'content.' + attrs.edit + '.data');
element.attr('onbeforesave', 'update($data, content.' + attrs.edit +'.id');
}
}
});
So, my first problem is that the xeditable directive doesn't work because it's inside of mine. I'm new to creating angularjs directives, but am wondering if it could have something to do with the way its being compiled?
My second problem is with the template. If my template just looks like this
template: '{{ ParamData }}'
Then it outputs the correct data, but I can't make it work without the other pieces to reference the scope data.
Also, here is what the view looks like using the directive
<h2 edit="portrait_description_title"></h2>
And here is what it would look like if I didn't use a directive to cut down on the boiler code
<h1 editable-text="content.portrait_description_title.data" onbeforesave="update($data, content.portrait_description_title.id)">
{{ content.portrait_description_title.data }}
</h1>
Thanks for any advice!
scope: {}you are creating a new scope, this is why you can't access the parent scope. Either don't create a child scope, or pass in the required element like you did with ParamData. Use transclusion to nest the directives (similar to how ng-repeat works, for example).