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="fok8du8" 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="dgmllbw" 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="zlouioe" id='qTiZP'><tfoot id='qTiZP'></tfoot><dl id='qTiZP'><fieldset id='qTiZP'></fieldset></dl></div>
                          主站蜘蛛池模板: 自动化改造_智虎机器人_灌装机_贴标机-上海圣起包装机械 | 沈阳楼承板_彩钢板_压型钢板厂家-辽宁中盛绿建钢品股份有限公司 轴承振动测量仪电箱-轴承测振动仪器-测试仪厂家-杭州居易电气 | 郑州外墙清洗_郑州玻璃幕墙清洗_郑州开荒保洁-河南三恒清洗服务有限公司 | 保镖公司-私人保镖-深圳保镖公司【环宇兄弟保镖】 | ★店家乐|服装销售管理软件|服装店收银系统|内衣店鞋店进销存软件|连锁店管理软件|收银软件手机版|会员管理系统-手机版,云版,App | 瓶盖扭矩仪(扭力值检测)-百科 | 避光流动池-带盖荧光比色皿-生化流动比色皿-宜兴市晶科光学仪器 东莞爱加真空科技有限公司-进口真空镀膜机|真空镀膜设备|Polycold维修厂家 | 生物除臭剂-除味剂-植物-污水除臭剂厂家-携葵环保有限公司 | 石家庄救护车出租_重症转院_跨省跨境医疗转送_活动赛事医疗保障_康复出院_放弃治疗_腾康26年医疗护送转诊团队 | LED显示屏_LED屏方案设计精准报价专业安装丨四川诺显科技 | 客服外包专业服务商_客服外包中心_网萌科技| 润滑脂-高温润滑脂-轴承润滑脂-食品级润滑油-索科润滑油脂厂家 | 罗茨真空机组,立式无油往复真空泵,2BV水环真空泵-力侨真空科技 | 双杰天平-国产双杰电子天平-美国双杰-常熟双杰仪器 | 阿尔法-MDR2000无转子硫化仪-STM566 SATRA拉力试验机-青岛阿尔法仪器有限公司 | SRRC认证_电磁兼容_EMC测试整改_FCC认证_SDOC认证-深圳市环测威检测技术有限公司 | 一体化污水处理设备-一体化净水设备-「山东梦之洁水处理」 | 煤棒机_增碳剂颗粒机_活性炭颗粒机_木炭粉成型机-巩义市老城振华机械厂 | 天津试验仪器-电液伺服万能材料试验机,恒温恒湿标准养护箱,水泥恒应力压力试验机-天津鑫高伟业科技有限公司 | 袋式过滤器,自清洗过滤器,保安过滤器,篮式过滤器,气体过滤器,全自动过滤器,反冲洗过滤器,管道过滤器,无锡驰业环保科技有限公司 | 体坛网_体坛+_体坛周报新闻客户端 | 即用型透析袋,透析袋夹子,药敏纸片,L型涂布棒-上海桥星贸易有限公司 | 电线电缆厂家|沈阳电缆厂|电线厂|沈阳英联塑力线缆有限公司 | 对辊式破碎机-对辊制砂机-双辊-双齿辊破碎机-巩义市裕顺机械制造有限公司 | 芝麻黑-芝麻黑石材厂家-永峰石业| 济南品牌包装设计公司_济南VI标志设计公司_山东锐尚文化传播 | 污水提升器,污水提升泵,地下室排水,增压泵,雨水泵,智能供排水控制器-上海智流泵业有限公司 | 实木家具_实木家具定制_全屋定制_美式家具_圣蒂斯堡官网 | POS机办理_个人POS机免费领取 - 银联POS机申请首页 | 带锯机|木工带锯机圆木推台锯|跑车带锯机|河北茂业机械制造有限公司| | 优考试_免费在线考试系统_培训考试系统_题库系统_组卷答题系统_匡优考试 | 工业硝酸钠,硝酸钠厂家-淄博「文海工贸」 | 保温杯,儿童婴童奶瓶,运动水壶「广告礼品杯定制厂家」超朗保温杯壶 | 智能交通网_智能交通系统_ITS_交通监控_卫星导航_智能交通行业 | 青岛美佳乐清洁工程有限公司|青岛油烟管道清洗|酒店|企事业单位|学校工厂厨房|青岛油烟管道清洗 插针变压器-家用电器变压器-工业空调变压器-CD型电抗器-余姚市中驰电器有限公司 | 无尘烘箱_洁净烤箱_真空无氧烤箱_半导体烤箱_电子防潮柜-深圳市怡和兴机电 | 网站建设,北京网站建设,北京网站建设公司,网站系统开发,北京网站制作公司,响应式网站,做网站公司,海淀做网站,朝阳做网站,昌平做网站,建站公司 | 挤出机_橡胶挤出机_塑料挤出机_胶片冷却机-河北伟源橡塑设备有限公司 | 四川职高信息网-初高中、大专、职业技术学校招生信息网 | 美侍宠物-专注宠物狗及宠物猫训练|喂养|医疗|繁育|品种|价格 | 软文发布平台 - 云软媒网络软文直编发布营销推广平台 |