I have a problem with data binding inside a directive that calls another directive.
Here is the basic directive:
var app = angular.module('app'); app.directive("myMainDirective", function ($http) { return { scope: { paramId: '=' }, link: function (scope) { $http.get('some/url/' + scope.paramId+ '.json' ).success(function (data) { scope.idFromServer = data; }); }, template: '<span other-directive id="idFromServer"></span>' } });
Here is another directive:
var app = angular.module('app'); app.directive("otherDirective", ['$http', function(http) { return { template: "<span>{{name}}</span>", scope: { id: "=" }, link: function(scope) { http.get('another/url/' + scope.id + '.json').then(function(result) { scope.name = result.data.name; }, function(err) { scope.name = "unknown"; }); } } }])
And the html code that is called by the main directive:
<span my-main-directive param-id="myObject.id"></span>
When calling "other-directive", "idFromServer" is not binding and "undefined", so it leads to diplay "undefined".
I probably miss something stupid, but I donβt see that ... (My piece of code is probably not the best, I am pretty new to angularjs, and especially directives, and I tried many ways to achieve what I want .)
source share