HTML
angular.element(document.querySelector('#dateControls')).append($compile("<search-date></search-date>")($scope));
Directive
myApp.directive('searchDate', function ($compile, $rootScope,$timeout) {
var linker = function (scope, element, attrs) {
var template = '<button class="btn btn-default" ng-click="dateSearch() id="playbackSearch" search-date">Search</button>';
element.html(template);
$compile(element.contents())(scope);
};
return {
restrict: "EA",
replace: true,
link: linker
};
});
Controller
$scope.dateSearch = function(){
scope.userId = 1;
myModuleService.getData(userId) //call service
then(function (data) {
console.log(data);
}).catch(function (error) {
throw error;
});
};
What is the method to execute the dateSearch()
function that was defined in my controller?