小编kbo*_*oul的帖子

限制字符并在角度js和离子后有三个点

我正在使用AngularJS和Ionic,我正在使用ng-bind-html从其他API中提取数据.我想限制字符数量,但在字符后面还有三个点,以显示用户还有更多要阅读的内容...

到目前为止,我有:

<p ng-bind-html="item.excerpt | limitTo: 100"></p>
Run Code Online (Sandbox Code Playgroud)

但这只会限制角色并将其切断.

javascript angularjs ionic-framework

2
推荐指数
2
解决办法
1万
查看次数

返回语句在Angular中不适用于对象

非常基本的东西......似乎它应该工作,但不是

这两个控制台日志都会吐出正确的信息.

$scope.getCurrentAttachment = function() {
  angular.forEach(attachments, function(attachment) {
    console.log(attachment);
    if(attachment.active) {
      console.log(attachment);
      return attachment;
    }
  });
};
Run Code Online (Sandbox Code Playgroud)

但后来在文件中调用它变得未定义

$scope.save = function() {
  console.log( $scope.getCurrentAttachment());
  var data = [$scope.labels.selected, $scope.getCurrentAttachment()];
  console.log(data);
  $uibModalInstance.close(data);
};
Run Code Online (Sandbox Code Playgroud)

任何帮助都会很有帮助.我不知道为什么这不起作用

javascript frontend client object angularjs

2
推荐指数
1
解决办法
141
查看次数

使用 axios 和 axios-mock-adapter

我试图在一个地方使用 axios 和 axios-mock-adapter 来聚合更多模拟,然后导出 axios 实例以在我想要的任何地方使用它:

模拟.js

import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';

let instance = axios.create({
    baseURL: 'https://some-domain.com/api/',
    timeout: 1000,
    headers: {'X-Custom-Header': 'foobar'}
});

let mock = new MockAdapter(instance);
mock.onGet('/users').reply(200, {
    users: [
        { id: 1, name: 'John Smith' }
    ]
});

export {instance}
Run Code Online (Sandbox Code Playgroud)

main.js

import instance from './mock'

instance.get('/users')
  .then(function(response) {
    console.log(response.data);
});
Run Code Online (Sandbox Code Playgroud)

但我收到这个错误:

Uncaught TypeError: Cannot read property 'get' of undefined
Run Code Online (Sandbox Code Playgroud)

谁能帮我?我错过了什么?

javascript axios axios-mock-adapter

1
推荐指数
1
解决办法
7788
查看次数

传单绘制事件“draw:deleted”不删除图层

请注意,我正在为 Angular 使用 @asymmetrik/ngx-leaflet-draw 。我正在配置一个地图,用户可以在其中绘制矩形或多边形。然后我将它们保存到基于 onDrawCreated 事件的 LayerGroup 中,这工作得很好。

我还打算根据 onDrawDeleted 事件删除图层,但由于某种原因,这不起作用。我最终在应用程序中做的是保存数据并将其转换为 GeoJSON。然后将其显示在控制台中以进行故障排除。

组件 HTML:

<button (click)="checked = !checked">Edit Mode</button>
<button (click)="onSave()">Save</button>
<div id="image-map" 
leaflet 
[leafletOptions]="options" 
[leafletLayersControl]="layersControl"
    (leafletMapReady)="onMapReady($event)">
    <div *ngIf="checked" 
    leafletDraw 
    [leafletDrawOptions]="drawOptions" 
    (leafletDrawCreated)="onDrawCreated($event)" 
    (leafletDrawDeleted)="onDrawDeleted($event)">
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

部分地图和传单绘制组件:

  zones = L.featureGroup();

  onDrawCreated(e: any) {
    this.zones.addLayer(e.layer);
    console.log('Draw Created Event!', e);
    console.log(this.zones.getLayers());
  }

  onDrawDeleted(e: any) {
    this.zones.removeLayer(e);
    console.log('Draw Deleted Event!', e);
    console.log(this.zones.getLayers());
  }

  onSave() {
    const data = this.zones.toGeoJSON();
    console.log(data);
  }
Run Code Online (Sandbox Code Playgroud)

根据文档和其他类似问题,上述代码应该可以工作。但我想我错过了一些简单的事情。

leaflet typescript leaflet.draw angular ngx-leaflet

1
推荐指数
1
解决办法
2259
查看次数

React 传单地图中心不变

我正在设置一个地图来查找一个人的坐标,然后将该位置放在地图上。但由于某种原因,坐标没有显示在地图上。我使用 console.log 确保状态变量(存储坐标的位置)发出正确的坐标,而且确实如此。我不知道为什么地图不会改变给他们。

我的代码:

import { StatusBar } from "expo-status-bar";
import React from "react";
import { StyleSheet, Text, View } from "react-native";
import { MapContainer, TileLayer, Marker, Popup } from "react-leaflet";
import Constants from "expo-constants";
import * as Location from "expo-location";
import * as Permissions from "expo-permissions";
import { render } from "react-dom";

import "leaflet/dist/leaflet.css";

export default class App extends React.Component {
  constructor() {
    super();
    this.state = {
      ready: false,
      where: { lat: '', lng: '' },
      error: null,
    }; …
Run Code Online (Sandbox Code Playgroud)

javascript leaflet reactjs react-leaflet

1
推荐指数
1
解决办法
2351
查看次数

如何在传单地图中设置标记图标?

我有我的组件 MAP 并且使用传单(不是反应传单)。我想设置一个标记。

这是我的组件的代码。

import React from 'react';
import L from 'leaflet';
import '../../../../node_modules/leaflet/dist/leaflet.css';
import './map.scss';



export default class Map extends React.Component {


  componentDidMount() {

    this.map = L.map('map', {
      center: [48.8762, 2.357909999999947],
      zoom: 14,
      zoomControl: true,
      layers: [
        L.tileLayer('https://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png',{
          detectRetina: true,
          maxZoom: 20,
          maxNativeZoom: 17,
        }),
      ]
    });

    L.marker([48.8762, 2.357909999999947],
      {
        draggable: true,        // Make the icon dragable
        title: 'Hover Text',     // Add a title
        opacity: 0.5}            // Adjust the opacity
    )
      .addTo(this.map)
      .bindPopup("<b>Paris</b><br>Gare de l'Est")
      .openPopup();

    L.circle([48.8762, 2.357909999999947], { …
Run Code Online (Sandbox Code Playgroud)

javascript leaflet reactjs

0
推荐指数
1
解决办法
7052
查看次数

使用 react-leaflet 2.0 进行标记聚类 (Leaflet.markercluster)

试图让 Leaflet.markercluster 与 react-leaflet 2 一起工作。

https://github.com/OpenGov/react-leaflet-cluster-layer似乎与 2.x 不兼容。

感谢任何让我入门的示例代码!

javascript leaflet reactjs leaflet.markercluster react-leaflet

-1
推荐指数
1
解决办法
4388
查看次数