Javascript 在角度方向上更改异步传入的数据
我有指示:Javascript 在角度方向上更改异步传入的数据,javascript,angularjs,asynchronous,angularjs-directive,angularjs-scope,Javascript,Angularjs,Asynchronous,Angularjs Directive,Angularjs Scope,我有指示: angular.module('mymodule').directive('someName', ['$http', function($http) { return { restrict: 'AE', scope: { headerId: '=header', data: '=data' }, templateUrl: 'path/to/template.html
angular.module('mymodule').directive('someName', ['$http', function($http) {
return {
restrict: 'AE',
scope: {
headerId: '=header',
data: '=data'
},
templateUrl: 'path/to/template.html',
compile: function() {
return function($scope, $link, $attr) {
console.log($scope.headerId); // print actual header id
console.log($scope.data); // undefined
/* ... code ... */
点is标头在指令属性中硬编码为数字。一切都很好。但数据是从具有angular服务的服务器异步获取的。因此,在编译函数运行时,$scope中没有数据。我的问题是,我想更改数据,以便它可以被指令模板读取
我如何才能做到这一点?将观察者添加到数据中
作用域.$watch('data',function(){…})