AngularJS directive with asynchronous parameters in scope
<p>I am trying to make a directive for an easier access to the static datas in my app. In my $rootScope, I have a params object which contains static datas coming from the backend server. The goal of this directive is to access to the params object easy in the html code. There are 2 parameters :</p>

<ul>
<li>param-name which contains the name of the requested object</li>
<li>param-id which contain the key of the object to access</li>
</ul>

<p>The result is the title attribute of the request object.</p>

<p>In my HTML code, I have</p>

<pre><code>&lt;ng-params param-name="ContactOrigins" param-id="contact.origin_id"&gt;&lt;/ng-params&gt;
</code></pre>

<p>In my JS code, I have :</p>

<pre><code>myApp.directive('ngParams',
    function($rootScope){
        return{
            restrict: 'E',
            template : '&lt;span&gt;{{value}}&lt;/span&gt;',
            scope: {
                paramName: '@',
                paramId: '='
            },
            link: function(scope,element,attrs){
                var tab = $rootScope.params[scope.paramName];
                console.log(scope.paramId);
                scope.value = '';
                for(var i = 0; i &lt; tab.length; i++) {
                    if(tab[i]['id'] == scope.paramId) {
                        scope.value = tab[i]['title'];
                    }
                };
                if(scope.value == '')
                    scope.value = '&lt;em&gt;Not specified&lt;/em&gt;'
            }
        }
    }
);
</code></pre>

<p>When the page is loaded, the <code>console.log(scope.paramId)</code> give me an "undefined" result. So it doesn't work properly.
The thing is that the object <code>contact</code> is loaded asynchronously through an $http request to the backend server. And my idea is that the $http request is not yet resolved and the directive tries to operate with an empty object.
A last additional point : The directive works perfectly when I put an hard coded value in the param-id attribute (<code>param-id="3"</code> for example).</p>

<p>My first question is : Am I right with my idea ?
My second question is : Is there any way to workaround this problem ? Is it possible to postpone the directive compilation until the $http is resolved ?</p>