In the code below, I am trying to use a template (with {{ value }}
substitution) but I have been trying for two days to find a way of getting to the rendered code to set some properties on it.
I cannot use the style selector (which works fine), I need to use the div's id. In my real code I use a templateUrl:
, not the inline code, but it has the same result.
Which event should I be listening for? At what point in time will the selectors work? I have read about compiling and linking and think the answer is out there somewhere?
Thanks in advance ...
<!doctype html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="utf-8">
<title>My AngularJS App</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
</head>
<body style="height:100%; width: 100%;">
<tls-window window-id="fred" window-width="600" window-label-width="150"></tls-window>
<script src="lib/angular/angular.js"></script>
<script src="js/app.js"></script>
<script src="js/core/services.js"></script>
<script src="js/core/controllers.js"></script>
<script src="js/core/filters.js"></script>
<script src="js/core/directives.js"></script>
<script src="js/core/tlscore-directives.js"></script>
<script type="text/javascript">
var coreDirectives = angular.module('tlsCore.directives', []);
coreDirectives.directive('tlsWindow', function() {
return {
restrict: 'E',
scope: {
windowId: '@windowId',
windowWidth: '@windowWidth',
labelWidth: '@windowLabelWidth'
},
replace: true,
transclude: false,
template: '<div id="{{windowId}}" class="tls-window" ng-cloak tls-draggable >' +
'<div id="{{windowId}}-winBackground" class="tls-window-background" style="width: 300px; height: 200px" >' +
'<div id="{{windowId}}-winToolbarBackground" class="tls-window-toolbar-background">' +
'<div id="{{windowId}}-winToolbarContent" class="tls-window-toolbar-content" style="width: 300px; height: 100px">' +
'</div>' +
'</div>' +
'</div>',
link: function(scope, element, attrs) {
var ele = element.get(element.index(scope.windowId));
// this works and sets the colour (by class)
$('.tls-window-toolbar-content').css("background-color", 'red');
// this does not work as the id of the element is not yet substituted and rendered ??
$('#fred-winBackground').css("background-color", 'green');
}
}
});
</script>
</body>
</html>