I'm rephrasing my question after reading awesome post provided by @charlietfl. And tried to remove jquery, as possible
There are couple of issues which I'm not able to get rid off.
- How to use angular modules on Parse Cloud.
- Since I don't know how to use Angular on Parse Cloud, I'm not able to create template which I can dynamically load.
So, to work around my 2nd issue, I've no option other than replacing the DOM dynamically(which is bad, I know). There is another requirement, with each div, I want menu to pop-up when user long-presses the div.
So for that I've created another directive long-press
and passing it with the DOM.
This is getting loaded from Parse Cloud Server
for (task in subTasks) {
var subTaskObj = subTasks[task];
var taskTitle = subTaskObj.title;
var taskStatus = subTaskObj.status;
// Here I'm passing long-press directive
taskDOM += '<div class="oaerror danger" long-press>' +
'<div class="col-xs-11"><strong>' + taskTitle + '</strong></div>' +
'<div class="col-xs-1 pull-right"><img src="images/volunteer-task.png"></div>' +
'<div class="clearfix"></div>' +
'</div>';
}
tg-dynamic directive
angular.module('DWrapper.directives')
.directive('tgDynamic', function($compile, WidgetService) {
return {
restrict: 'E',
scope: {
groupWidget: '@'
},
template: '<div/>',
replace: true,
link: function(scope, ele, attr) {
scope.$watch('groupWidget', function(newVal) {
if (newVal) {
widgetService.getWidgetTemplate({"groupWidgetId": newVal })
.then(function(widgetResponse) {
var template = widgetResponse.data.result.template;
$(ele).html($compile(template)(scope));
});
}
});
}
};
});
In the image, scope is available only on the root element, and not on long-press directive
So, how to inject scope, for the dynamically added long-press
directive to work.