I'm quite new to AngularJS so I try to understand it. Thus, don't shoot me when you read the initial question.
I'm developping an application using AngularJS. The HTML looks somehow like this:
<div id="OfficeUI" ng-controller="Office as Office">
<div class="absolute">
<div class="container application-icons icon">
<img id="{{icon.Id}}" ng-repeat-start="icon in Office.Icons" ng-repeat-end ng-src="{{icon.Icon}}" alt="{{icon.Alt}}" />
</div>
</div>
</div>
The controller of my application looks like:
var OfficeUI = angular.module('Office');
// Defines the Office controller for the application.
OfficeUI.controller('Office', ['$http', function($http) {
// Defines required variables.
var application = this;
// Get the Json file 'application.json' that defines the application data.
$http.get('/OfficeUI.Beta/Resources/JSon/application.json')
.success(function(data) {
application.Title = data.Title;
application.Icons = data.Icons;
})
.error(function(data) {
console.error('An error occured while loading the \'application.json\' file.');
});
}]);
As you see in the HTML, I'm binding image elements based on the data which is found in a particular JSon file.
Now, I want the user to give the possibility to add an event to a given element (in this case an image). Herefore, I've developped a jQuery plugin that looks like:
(function ( $ ) {
$.fn.OfficeUI = function(options) {
var settings = $.extend({
}, $.fn.OfficeUI.Defaults, options);
return this;
}
$.fn.OfficeUI.Defaults = { };
$.fn.OfficeUI.bind = function(elementSelector, bound, action) {
$(elementSelector).on(bound, function() { action(); });
return this;
};
}(jQuery));
This plugin allows me to call add an event as following:
$(this).OfficeUI.bind("icoApplication", "click", function() {
console.log('The following element is bound.');
});
However, the first parameter of the function takes a selector to find the element to attach the event to. But in AngularJS this isn't working since the elements are not created yet.
Anyone who has an idea on how to resolve this issue? I do want to provide a clean, minimalistic way for users to bind events to the application, without modifying existing controllers, directives, filters, ...
Thanks in advance.