0

I am trying to understand how to pass data through my directive so that I can bind it at the view level. I believe I understand the separation of controller scope vs. the directive isolate scope but I cant seem to get a simple json result out to my view. My JSFiddle can be found here http://jsfiddle.net/jamesamuir/2KLVj/4/.

app.directive('testList', function (testService) {
    return {
        restrict: 'A',

        link: function ($scope, element, attrs) {

            $scope.name = 'isolate scope';
            $scope.data = {};
            $scope.data.loadtext = testService.getJSON().then(function (data) {
                alert(data);
                element.addClass("red");

            });
        }
    }
});

It seems to me that this should work but, alas, it does not. Any help would be greatly appreciated.

4

1 回答 1

2

在您的then()回调中,分配datadata.loadtext

testService.getJSON().then(function (data) {
   alert(data);
   element.addClass("red");
   scope.data.loadtext = data;
});

fiddle

于 2013-05-18T03:00:55.640 回答