You need to pass the function $timeout :
$timeout(function() { console.log('timeout: view 1 linked') }, 0);
Or:
var fn = function () { console.log('timeout: view 1 linked'); }; $timeout(fn, 0);
Following:
$timeout(console.log('timeout: view 1 linked'), 0);
Run console.log instantly, then pass the return value ( undefined ) as the first argument to $timeout .
Demo: http://plnkr.co/edit/zWgoJihcMH693fWfUp09?p=preview
Not sure if you have the same problem in your real application, but I thought I should post this anyway.
New answer based on editing
The problem is that your link element is in the view template, not in index.html.
If you move it to index.html, it will work as you expect (in which case you will not need $timeout , unless your real application adds custom HTML from the directive):
Demo: http://plnkr.co/edit/m3sriF2YYH5T8y42R5Lr?p=preview
If you save the link in the view template and save the timeout, this basically happens:
- Angular will perform its compilation function to prepare all the bindings and views.
- HTML from the views will be inserted into the DOM, directives will be executed, and
console.log will be added to the timeout queue. - The link element is now pasted into the DOM and the browser will start retrieving CSS. Console.log is
console.log in the wait queue.
Please note that CSS fetching is asynchronous, and console.log from the timeout queue will be executed until CSS fetching and parsing is complete.
Also note that in different browsers you can see different types of behavior.
There are solutions, but it can get really dirty.
To learn more about this:
When is the stylesheet really loaded?
I would recommend just moving the link to index.html.