Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 服务中指令的访问链接_Javascript_Angularjs_Service_Directive - Fatal编程技术网

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);
    }
   };
});