【发布时间】:2015-04-07 16:19:10
【问题描述】:
我想实现一个具有隔离作用域的指令和一个双向绑定到异步加载数据的控制器作用域的指令。
部分html:
<body ng-app = 'authorGraph' ng-controller = 'GraphCtrl'>
<graph-dir/>
Javascript:
var authorGraph = angular.module('authorGraph', []);
authorGraph.directive('graphDir', function () {
return {
scope: {
graphData: '=' //two way binding
},
restrict: 'E',
link: function (scope, element) {
//do something with D3.js to visualise the data here
}
};
浏览互联网,我发现 Promise 可以解决问题(此代码位于指令实现之前)
authorGraph.config(function($routeProvider) {
$routeProvider.when('/',
{
controller: 'GraphCtrl',
resolve: {
getData: function ($http) {
return $http.get('graph_data.json').then(function (data) {
return data;
});
}
}
});
});
authorGraph.controller('GraphCtrl', function GraphCtrl($scope, getData) {
$scope.graphData = getData;
});
但是,我被错误困住了
未知提供者:getDataProvider
【问题讨论】:
标签: angularjs asynchronous angularjs-directive angularjs-scope