pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    • <bdo id='jx7dz'></bdo><ul id='jx7dz'></ul>
    <i id='jx7dz'><tr id='jx7dz'><dt id='jx7dz'><q id='jx7dz'><span id='jx7dz'><b id='jx7dz'><form id='jx7dz'><ins id='jx7dz'></ins><ul id='jx7dz'></ul><sub id='jx7dz'></sub></form><legend id='jx7dz'></legend><bdo id='jx7dz'><pre id='jx7dz'><center id='jx7dz'></center></pre></bdo></b><th id='jx7dz'></th></span></q></dt></tr></i><div class="qcq2mmq" id='jx7dz'><tfoot id='jx7dz'></tfoot><dl id='jx7dz'><fieldset id='jx7dz'></fieldset></dl></div>
  1. <small id='jx7dz'></small><noframes id='jx7dz'>

  2. <legend id='jx7dz'><style id='jx7dz'><dir id='jx7dz'><q id='jx7dz'></q></dir></style></legend>
    1. <tfoot id='jx7dz'></tfoot>

      如何在 Leaflet 標記彈出窗口中使用 Angular 指令

      How to use Angular directives ng-click and ng-class inside Leaflet marker popup(如何在 Leaflet 標記彈出窗口中使用 Angular 指令 ng-click 和 ng-class)

      <small id='WbEf8'></small><noframes id='WbEf8'>

      <i id='WbEf8'><tr id='WbEf8'><dt id='WbEf8'><q id='WbEf8'><span id='WbEf8'><b id='WbEf8'><form id='WbEf8'><ins id='WbEf8'></ins><ul id='WbEf8'></ul><sub id='WbEf8'></sub></form><legend id='WbEf8'></legend><bdo id='WbEf8'><pre id='WbEf8'><center id='WbEf8'></center></pre></bdo></b><th id='WbEf8'></th></span></q></dt></tr></i><div class="wseueog" id='WbEf8'><tfoot id='WbEf8'></tfoot><dl id='WbEf8'><fieldset id='WbEf8'></fieldset></dl></div>
        <tbody id='WbEf8'></tbody>
      • <tfoot id='WbEf8'></tfoot>

            • <legend id='WbEf8'><style id='WbEf8'><dir id='WbEf8'><q id='WbEf8'></q></dir></style></legend>
              • <bdo id='WbEf8'></bdo><ul id='WbEf8'></ul>

                本文介紹了如何在 Leaflet 標記彈出窗口中使用 Angular 指令 ng-click 和 ng-class的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在使用 Angular.JS 和 Leaflet.JS 作為我所在位置的地圖,該地圖具有綁定了彈出窗口的地圖標記.我需要使用一個帶有兩個不同圖標(一個在下面的代碼中顯示)的跨度,您可以單擊它們來調用不同的函數,并在滿足某些條件時使用 ng-class 來更改類.這是我的代碼:

                I'm using Angular.JS and Leaflet.JS for a map in my location that has map markers with popups binded to them. I need to use a span with two different icons (one shown in code below) that you can click to call different functions and with ng-class to change the class if certain conditions are met. This is my code:

                var marker = L.marker([51.5, -0.09], {icon: blueIcon}).bindPopup('<br><span ng-class="thumbsUpClass(' + hotelsSelectedDates[i]['hotels'][s] + ')" ng-click="addChoice(' + hotelsSelectedDates[i]['hotels'][s] + ',' + hotels + ')"><span class="popup-container"><span class="icon-stack thumbs-up-stack"><i class="icon-sign-blank icon-stack-base"></i><i class="icon-thumbs-up"></i></span></span></span>');
                

                但是,當我檢查元素時,我得到了這個:

                However when I inspect the element I get this:

                <span ng-class="thumbsUpClass([object Object])" ng-click="addChoice([object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object])"><span class="popup-container"><span class="icon-stack thumbs-up-stack"><i class="icon-sign-blank icon-stack-base"></i><i class="icon-thumbs-up"></i></span></span></span>
                

                ng-click 應該向該函數發送特定對象和對象數組,但是當我單擊圖標時沒有任何反應.在我的研究中,我發現彈出窗口會阻止事件傳播(更多信息但我不是確定如何覆蓋它或修復它以使其與 Angular 一起使用.有人知道如何完成此操作嗎?

                The ng-click should send that function both the specific object and the array of objects but when I click the icon nothing happens. In my research I found that the popup prevents event propagation (more info but I'm not sure how to override it or a fix to get it to work with angular. Would anyone have an idea of how to accomplish this?

                更新:

                由于 ng-click/class 評估一個字符串,我將變量固定為:

                Since ng-click/class evaluate a string I fixed the variables to be like this:

                $scope.item = hotelsSelectedDates[i]['hotels'][s]
                $scope.set = hotels
                var marker = L.marker([51.5, -0.09], {icon: blueIcon}).bindPopup('<br><span ng-class="thumbsUpClass(item)" ng-click="addChoice(item,set)"><span class="popup-container"><span class="icon-stack thumbs-up-stack"><i class="icon-sign-blank icon-stack-base"></i><i class="icon-thumbs-up"></i></span></span></span>');
                

                然后 html 會正確輸出:

                The html then comes out correctly:

                <span ng-class="thumbsUpClass(item)" ng-click="addChoice(item,set)"><span class="popup-container"><span class="icon-stack thumbs-up-stack"><i class="icon-sign-blank icon-stack-base"></i><i class="icon-thumbs-up"></i></span></span></span>
                

                但是,當我單擊該圖標時,什么也沒有發生,并且看起來函數沒有被調用.有人知道為什么會發生這種情況嗎?

                However when I click the icon nothing happens and it doesn't look like the functions are being called. Anyone have any clue why this would happen?

                推薦答案

                您的問題來自于您手動創建了一些 DOM,而這些 DOM 不是由 AngularJS 編譯的.

                Your issue comes from the fact that you are manually creating some DOM, which was not compiled by AngularJS.

                在這些情況下,您必須手動編譯和鏈接元素.

                In those cases, you have to manually compile and link the element.

                代碼如下所示:

                var html = '<br><span ng-class="thumbsUpClass(item)" ' +
                    'ng-click="addChoice(item,set)"><span class="popup-container"><span ' +
                    'class="icon-stack thumbs-up-stack"><i class="icon-sign-blank ' +
                    'icon-stack-base"></i><i class="icon-thumbs-up"></i></span></span></span>',
                    linkFunction = $compile(angular.element(html)),
                    newScope = $scope.$new();
                
                newScope.item = hotelsSelectedDates[i]['hotels'][s]
                newScope.set = hotels
                var marker = L.marker([51.5, -0.09], {icon: blueIcon}).bindPopup(linkFunction(newScope)[0]);
                

                在這里,我獲取您的 HTML 字符串,并首先將其轉換為 DOM.因為 AngularJS 吃的是 DOM,而不是字符串.

                Here I take your HTML string, and I start by transforming it into DOM. Because AngularJS eats DOM, not strings.

                angular.element(html)
                

                然后,我使用 $compile 服務將此 DOM 編譯為鏈接函數.

                Then, I compile this DOM into a link function, using the $compile service.

                linkFunction = $compile(angular.element(html));
                

                執行時,此函數將返回一個完全由 Angular 控制的 jQuery DOM 樹,并在您作為參數提供給它的范圍內運行.這就是我在這里所做的

                When executed, this function will return a jQuery DOM tree fully controlled by Angular, running in the scope you give to it as argument. This is what I do here

                linkFunction(newScope)
                

                請注意,我給出的范圍是 $scope 的子范圍.如果不這樣做,您將在所有彈出窗口之間共享相同的范圍,這不是一個好主意.創建新范圍是在 var 聲明中完成的

                Please note that the scope I give is a child scope of $scope. Without doing this, you would share the same scope between all popups, and this would not be a good idea. Creating the new scope was done in the var declaration

                newScope = $scope.$new()
                

                從中可以得到實際的 DOM 節點

                From that you can get the actual DOM node

                linkFunction(scope)[0]
                

                并將其傳遞給 Leaflet

                And pass it to Leaflet

                .bindPopup(linkFunction(newScope)[0]);
                

                你就完成了!

                有關詳細信息,請參閱 compiler 文檔.

                For more info, please refer to the compiler doc.

                關于范圍的更正問題

                這篇關于如何在 Leaflet 標記彈出窗口中使用 Angular 指令 ng-click 和 ng-class的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Check if a polygon point is inside another in leaflet(檢查一個多邊形點是否在傳單中的另一個內部)
                Changing leaflet markercluster icon color, inheriting the rest of the default CSS properties(更改傳單標記群集圖標顏色,繼承其余默認 CSS 屬性)
                Trigger click on leaflet marker(觸發點擊傳單標記)
                How can I change the default loading tile color in LeafletJS?(如何更改 LeafletJS 中的默認加載磁貼顏色?)
                Add external geojson to leaflet layer(將外部geojson添加到傳單層)
                Adding Leaflet layer control to sidebar(將 Leaflet 圖層控件添加到側邊欄)
                • <small id='qTiZP'></small><noframes id='qTiZP'>

                      <tbody id='qTiZP'></tbody>
                    • <bdo id='qTiZP'></bdo><ul id='qTiZP'></ul>

                      <tfoot id='qTiZP'></tfoot>

                        <legend id='qTiZP'><style id='qTiZP'><dir id='qTiZP'><q id='qTiZP'></q></dir></style></legend>

                        1. <i id='qTiZP'><tr id='qTiZP'><dt id='qTiZP'><q id='qTiZP'><span id='qTiZP'><b id='qTiZP'><form id='qTiZP'><ins id='qTiZP'></ins><ul id='qTiZP'></ul><sub id='qTiZP'></sub></form><legend id='qTiZP'></legend><bdo id='qTiZP'><pre id='qTiZP'><center id='qTiZP'></center></pre></bdo></b><th id='qTiZP'></th></span></q></dt></tr></i><div class="ggaokwg" id='qTiZP'><tfoot id='qTiZP'></tfoot><dl id='qTiZP'><fieldset id='qTiZP'></fieldset></dl></div>
                          主站蜘蛛池模板: 农业四情_农业气象站_田间小型气象站_智慧农业气象站-山东风途物联网 | 桨叶搅拌机_螺旋挤压/方盒旋切造粒机厂家-无锡市鸿诚输送机械有限公司 | 拉力机-拉力试验机-万能试验机-电子拉力机-拉伸试验机-剥离强度试验机-苏州皖仪实验仪器有限公司 | 希望影视-高清影视vip热播电影电视剧免费在线抢先看 | 济南玻璃安装_济南玻璃门_济南感应门_济南玻璃隔断_济南玻璃门维修_济南镜片安装_济南肯德基门_济南高隔间-济南凯轩鹏宇玻璃有限公司 | 必胜高考网_全国高考备考和志愿填报信息平台 | 机房监控|动环监控|动力环境监控系统方案产品定制厂家 - 迈世OMARA | 哲力实业_专注汽车涂料汽车漆研发生产_汽车漆|修补油漆品牌厂家 长沙一级消防工程公司_智能化弱电_机电安装_亮化工程专业施工承包_湖南公共安全工程有限公司 | 房间温控器|LonWorks|海思| 锂电叉车,电动叉车_厂家-山东博峻智能科技有限公司 | 可程式恒温恒湿试验箱|恒温恒湿箱|恒温恒湿试验箱|恒温恒湿老化试验箱|高低温试验箱价格报价-广东德瑞检测设备有限公司 | 路面机械厂家| 富森高压水枪-柴油驱动-养殖场高压清洗机-山东龙腾环保科技有限公司 | 闪蒸干燥机-喷雾干燥机-带式干燥机-桨叶干燥机-[常州佳一干燥设备] | 柔性测斜仪_滑动测斜仪-广州杰芯科技有限公司 | 深圳激光打标机_激光打标机_激光焊接机_激光切割机_同体激光打标机-深圳市创想激光科技有限公司 深圳快餐店设计-餐饮设计公司-餐饮空间品牌全案设计-深圳市勤蜂装饰工程 | 医疗仪器模块 健康一体机 多参数监护仪 智慧医疗仪器方案定制 血氧监护 心电监护 -朗锐慧康 | 山东集装箱活动房|济南集装箱活动房-济南利森集装箱有限公司 | 棕刚玉_白刚玉_铝酸钙-锐石新材料 | 撕碎机,撕破机,双轴破碎机-大件垃圾破碎机厂家 | 骁龙云呼电销防封号系统-axb电销平台-外呼稳定『免费试用』 | 焊接烟尘净化器__焊烟除尘设备_打磨工作台_喷漆废气治理设备 -催化燃烧设备 _天津路博蓝天环保科技有限公司 | 礼仪庆典公司,礼仪策划公司,庆典公司,演出公司,演艺公司,年会酒会,生日寿宴,动工仪式,开工仪式,奠基典礼,商务会议,竣工落成,乔迁揭牌,签约启动-东莞市开门红文化传媒有限公司 | 整合营销推广|营销网络推广公司|石家庄网站优化推广公司|智营销 好物生环保网、环保论坛 - 环保人的学习交流平台 | 电竞学校_电子竞技培训学校学院-梦竞未来电竞学校官网 | 软装设计-提供软装装饰和软装配饰及软装陈设的软装设计公司 | 骨密度仪-骨密度测定仪-超声骨密度仪-骨龄测定仪-天津开发区圣鸿医疗器械有限公司 | 吊篮式|移动式冷热冲击试验箱-二槽冷热冲击试验箱-广东科宝 | 沥青车辙成型机-车托式混凝土取芯机-混凝土塑料试模|鑫高仪器 | 防水套管厂家-柔性防水套管-不锈钢|刚性防水套管-天翔管道 | 河南档案架,档案密集架,手动密集架,河南密集架批发/报价 | 珠海白蚁防治_珠海灭鼠_珠海杀虫灭鼠_珠海灭蟑螂_珠海酒店消杀_珠海工厂杀虫灭鼠_立净虫控防治服务有限公司 | 衡阳耐适防护科技有限公司——威仕盾焊接防护用品官网/焊工手套/焊接防护服/皮革防护手套 | 珠海冷却塔降噪维修_冷却塔改造报价_凉水塔风机维修厂家- 广东康明节能空调有限公司 | 净化车间装修_合肥厂房无尘室设计_合肥工厂洁净工程装修公司-安徽盛世和居装饰 | 作文导航网_作文之家_满分作文_优秀作文_作文大全_作文素材_最新作文分享发布平台 | 东风体检车厂家_公共卫生体检车_医院体检车_移动体检车-锦沅科贸 | 无锡不干胶标签,卷筒标签,无锡瑞彩包装材料有限公司 | 营养师网,营养师考试时间,报名入口—网站首页 | 搜木网 - 木业全产业链交易平台,免费搜货、低价买货! | PO膜_灌浆膜及地膜供应厂家 - 青州市鲁谊塑料厂 |