简体   繁体   English

我如何从angular之外的javascript函数中获取angular js创建的对象的实例

[英]How can i get an instance of object created by angular js from javascript function outside angular

I have angular app written well, but i have to access an instance of an object created by angular, below is the angular code; 我的角度应用程序写得很好,但是我必须访问一个由角度创建的对象的实例,下面是角度代码;

inside it, there is [g.mapInstance = i =....] line. 里面有[g.mapInstance = i = ....]行。 I have to access the map instance with pure javascript outside angular. 我必须使用angular之外的纯JavaScript访问地图实例。 I hope i am clear about my question. 我希望我清楚我的问题。 Thanks alot... 非常感谢...

    a.module("myapp.maps", []).value("mapsConfig", {}).factory("mapsApi", ["$window", "$q", "mapsConfig", function(a, b, c) {
    return b(function(b) {
        var d = c.apiKey || "",
            e = c.libraries || [],
            f = e.join(",");
        a.__handleApiReady = function() {
            b(google.maps)
        };
        $script("//maps.googleapis.com/maps/api/js?sensor=false" + (d ? "&key=" + d : "") + (f ? "&libraries=" + f : "") + "&callback=__handleApiReady")
    })
}]).directive("maps", ["mapsApi", function(c) {
    return {
        restrict: "A",
        replace: true,
        transclude: true,
        scope: {
            center: "=center",
            zoom: "=zoom",
            dragging: "=dragging",
            control: "=",
            options: "=options",
            events: "=events",
            styles: "=styles",
            bounds: "=bounds",
            geocode: "="
        },
        template: '<div><div class="map-container"></div><div ng-transclude style="display: none"></div></div>',
        controller: ["$scope", "$element", "$attrs", function(d, e, f) {
            var g = this,
                h = d.events,
                i;
            c.then(function(c) {
                var j = {
                        zoom: 14,
                        mapTypeId: c.MapTypeId.ROADMAP,
                        mapTypeIds: [c.MapTypeId.ROADMAP, c.MapTypeId.HYBRID],
                        mapTypeControlOptions: {
                            style: c.MapTypeControlStyle.HORIZONTAL_BAR,
                            position: c.ControlPosition.TOP_RIGHT,
                            mapTypeIds: [c.MapTypeId.ROADMAP, c.MapTypeId.SATELLITE]
                        },
                        zoomControl: true,
                        zoomControlOptions: {
                            style: c.ZoomControlStyle.SMALL
                        },
                        streetViewControl: false,
                        scrollwheel: false,
                        panControl: true,
                        panControlOptions: {
                            position: c.ControlPosition.TOP_LEFT
                        },
                        scaleControl: false,
                        scaleControlOptions: {
                            position: c.ControlPosition.BOTTOM
                        },
                        disableDoubleClickZoom: true
                    },
                    k = d.options;
                g.mapInstance = i = new c.Map(e.find("div")[0], a.extend({}, j, k));
                d.$watch("bounds", function(a) {
                    if (a && a.length === 4) {
                        i.fitBounds(new c.LatLngBounds(new c.LatLng(a[2], a[3]), new c.LatLng(a[0], a[1])))
                    }
                });
                d.$watch("geocode", function(a) {
                    if (a) {
                        var b = new c.Geocoder,
                            d;
                        b.geocode({
                            address: a
                        }, function(a, b) {
                            if (b == "OK" && a.length > 0) {
                                d = a[0].geometry;
                                i.setCenter(d.location);
                                if (d.hasOwnProperty("bounds")) {
                                    i.fitBounds(d.bounds)
                                }
                            }
                        })
                    }
                });
                if (h) {
                    a.forEach(h, function(a, b) {
                        c.event.addListener(i, b, function() {
                            a.apply(i, arguments)
                        })
                    })
                }
                a.forEach(f.$attr, function(e, g) {
                    if (g.indexOf("options") === 0 && g.length > 7) {
                        f.$observe(g, function(b) {
                            var c = {};
                            c[g.replace("options", "")] = b;
                            i.setOptions(a.extend({}, j, c))
                        })
                    }
                    if (g.indexOf("events") === 0 && g.length > 6) {
                        var h = b(g.replace("events", ""));
                        c.event.addListener(i, h.replace("-", "_"), function() {
                            d.$parent.$eval(f[g])
                        })
                    }
                })
            })
        }]
    }...... goes on

I got it. 我知道了。 Hope it helps soneone too.. Thanks to MorningDew for giving the clue. 希望它也能帮助到Soneone。.感谢MorningDew提供了线索。 below is solution 下面是解决方案

var s = angular.element(document.querySelector(".map-container")).scope(); 
var b = {}; b.latLng = {}; b.latLng.lat = function(){ return 41.005329; } ; 
b.latLng.lng = function(){return 28.891567; };
s.events.click(b);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过Javascript或Jquery从控制器外部调用Angular JS函数? - How do I call an Angular JS function from outside the controller via Javascript or Jquery? 使用javascript,angular.js和sql.js,如何从url获取文件对象? - using javascript, angular.js, and sql.js, how do I get a file object from a url? 从JS外部访问Angular对象的函数 - Access Angular object's function from outside JS angular js之外的Javascript - Javascript outside angular js 我如何在我的angular App之外调用一个javascript函数而不导入它 - How can I call a javascript function which is outside my angular App without importing it 如何从$ scope函数angular javascript外部访问变量? - how to access a variable from outside the $scope function angular javascript? 如何在功能之外访问数据-Angular / Javascript - How to Access data outside of Function - Angular/Javascript 如何获取多个Angular JS路由来共享一个控制器实例? - How can I get multiple Angular JS routes to share a single controller instance? 如何将$ user对象从drupal传递给Angular JS应用程序,以便角度可以使用它? - How do I pass the $user object from drupal to an Angular JS app so angular can use it? 如何从AIML调用angular / typescript函数? 如果不可能,如何使Javascript函数调用angular / typescript函数? - How can i call angular/typescript function from AIML? if not possible, how can i make Javascript function call angular/typescript function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM