Imagine having a module with a directive structured as follows (this is a rough, untested implementation) There are 3 fundamental requirements that need to be fulfilled:
- Set up configuration for the element display
- Add event listeners accessible by the base controller
- Create public methods that can be invoked by the base controller
angular.module("componentModule",[]) .directive("myComp",function(){
return{
replace:true,
template:'<h2>This is my component</h2>',
scope:{config= "@"},
link:function(scope,element,attr){
this.deleteElement = function(id){
//implementing code to delete this component
//You can call this API function to remove it
}
if (!scope.config.visible){
//element configuration object
this.visible(false)}
}
} })
Then in the main HTML file, include the directive like this:
<div myComm="first" config="eleConfig"></myComp>
<div myComm="second" config="newEleConfig"></myComp>
A separate controller is used for handling the main HTML:
angular.module("baseApp",['componentModule'])
.controller('baseCtrl',function(){
$scope.eleConfig = {
visible:true,
delete:function(e){
//This function will run when the delete method is called
}
}
//Call the delete method like this:
$scope.first.deleteElement();
})
Inquiry How can we trigger the deleteElement() method in the baseCtrl similar to how KENDO UI operates?