我正在使用AngularJS和Ionic,我正在使用ng-bind-html从其他API中提取数据.我想限制字符数量,但在字符后面还有三个点,以显示用户还有更多要阅读的内容...
到目前为止,我有:
<p ng-bind-html="item.excerpt | limitTo: 100"></p>
Run Code Online (Sandbox Code Playgroud)
但这只会限制角色并将其切断.
非常基本的东西......似乎它应该工作,但不是
这两个控制台日志都会吐出正确的信息.
$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)
任何帮助都会很有帮助.我不知道为什么这不起作用
我试图在一个地方使用 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)
谁能帮我?我错过了什么?
请注意,我正在为 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)
根据文档和其他类似问题,上述代码应该可以工作。但我想我错过了一些简单的事情。
我正在设置一个地图来查找一个人的坐标,然后将该位置放在地图上。但由于某种原因,坐标没有显示在地图上。我使用 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) 我有我的组件 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) 试图让 Leaflet.markercluster 与 react-leaflet 2 一起工作。
https://github.com/OpenGov/react-leaflet-cluster-layer似乎与 2.x 不兼容。
感谢任何让我入门的示例代码!
javascript leaflet reactjs leaflet.markercluster react-leaflet
javascript ×6
leaflet ×4
reactjs ×3
angularjs ×2
angular ×1
axios ×1
client ×1
frontend ×1
leaflet.draw ×1
ngx-leaflet ×1
object ×1
typescript ×1