I'm trying to build a "fold out" directive. The HTML always have a title and some content. The title should always be shown, and when you push the title, the content will be shown as well.
Also the content will bind to the view controller.
Controller.js:
app.controller('MyController', function(...) {
$scope.my_variable = "HELLO WORLD";
});
HTML:
<div roll-down>
<div id="open-on" class="title">
MY TITLE
</div>
<div class="content">
{{my_variable}} <--- controller, not directive.
</div>
</div>
RollDownDir.js:
app.directive('rollDown', function(...) {
var linkFn;
linkFn = function(scope, element, attrs) {
var title = element[0].querySelector('.title');
var content = element[0].querySelector('.content');
var content_buffer = angular.copy(content);
content.remove();
var addContent = function(){
element.append(content_buffer);
$compile(content_buffer)(scope);
}
angular.element(element).on('click', function (evt) {
addContent();
$ionicScrollDelegate.resize();
$rootScope.$apply();
scope.$apply();
});
};
return {
restrict: 'AEC',
link: linkFn
};
});
Now this works fine BUT, the binding in the controller "my_variable" will never be compiled. So it will just be empty? How can I overcome this?
I have to remove the content DOM completely for performance (it is for mobile application, and the content is heavy stuff like SVGs etc.).