Javascript 服务中指令的访问链接
是否可以访问服务中指令的链接或数据 我的服务:Javascript 服务中指令的访问链接,javascript,angularjs,service,directive,Javascript,Angularjs,Service,Directive,是否可以访问服务中指令的链接或数据 我的服务: myApp.service('myService', function () { this.analyze = function (data) { for (var i = 0; i < data.length; i++) { if( data[i].x == ) //<--- here i want to compare data with data in directive
myApp.service('myService', function () {
this.analyze = function (data) {
for (var i = 0; i < data.length; i++) {
if( data[i].x == ) //<--- here i want to compare data with data in directive
}
}
});
myApp.service('myService',函数(){
this.analyze=函数(数据){
对于(变量i=0;i 如果(数据[i].x==)//将元素作为参数传递给服务。控制器已调用该服务,我无法在指令中调用该服务,这将导致服务和指令之间共享元素的dataUse$rootScope出现问题。$rootScope是全局对象将元素作为参数传递给服务。控制器已调用该服务,我无法在服务的所有指令中,服务和指令之间共享元素的dataUse$rootScope都会出现问题
myApp.directive('dateInfo', function ($interval) {
return {
restrict: 'A',
scope: {
},
//templateUrl: '123/Scripts/directives/html/dateInfo.html',
link: function (scope, element, attrs) {
element.html('<div class="panel panel-primary">' +
'<div class="panel-heading">test</div>' +
'<div class="panel-body"></div></div>');
$interval(function () {
var rect = element[0].getBoundingClientRect();
x = rect.left;
y = rect.top;
w = rect.right - rect.left;
h = rect.bottom - rect.top;
}, 3000);
}
};
});