我的问题是关于从父组件访问childerns组件方法的方法.我找到了使用下面的例子描述的解决方案,但我担心我可能是错误的,而不是'angular2 right'的方式.
比如我们有孩子:
@Component({ ... })
export class Modal {
...
open() {
...
}
}
Run Code Online (Sandbox Code Playgroud)
和父母:
import { Modal } from '../common';
...
@Component({
selector: 'editor',
directives: [ Modal ],
templateUrl: './editor.html',
...
})
export class Editor {
_modal = null;
...
bindModal(modal) { this._modal=modal; }
open() {
this._modal.open();
}
}
Run Code Online (Sandbox Code Playgroud)
在editor.html中:
<button (click)="open()">Open Editor</button>
<modal #editModal>{{ bindModal(editModal) }}
Here is my editor body in modal (popup) window
...
</modal>
Run Code Online (Sandbox Code Playgroud)
这是从Editor组件访问open()Modal组件内部方法的解决方案.这有点棘手.问题是:如果没有使用'bindModal'方法,是否有最简单,更直接的方法?
API请求失败,因为由于我的配置,Axios生成的URL不正确。我知道请求网址看起来应该是什么样,所以我想看看Axios生成的请求网址。
我可以将Axios指向本地服务器并在其中查看请求,但是我想在客户端上调试它。我想玩配置,看看请求如何变化。有没有一种方法可以在发送之前或之后从Axios输出请求url?
// param format
{ address: 'Vancouver', key: GOOGLE_API_KEY }
// Geocode sample
https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY
_request = async (...args) => {
const { outputFormat, params } = args
const instance = axios.create({
baseURL: `https://maps.googleapis.com`,
})
const response = await instance.get('/maps/api/geocode/${outputFormat}?', {
params,
})
// I want to see the url generated by Axios so I can debug the issue
console.log(response)
}
Run Code Online (Sandbox Code Playgroud)
我是内Expo,React Native环境。
使用提取的工作示例:
const url = `https://maps.googleapis.com/maps/api/geocode/json?address=vancouver&key=${GOOGLE_API_KEY}`
fetch(url)
.then((response) => response.json())
.then((data) => {
console.log(data) …Run Code Online (Sandbox Code Playgroud) 我有电子邮件,想要在第一个字母和@到*之间替换每个字符.例:
john.smith@gmail.com -> j*********@gmail.com
Run Code Online (Sandbox Code Playgroud)
这是我的代码,但它产生一颗星而不是很多 - 我坚持下去:
let h="john.smith@gmail.com".replace(/(.)(.*)@/,'$1*')
console.log(h);Run Code Online (Sandbox Code Playgroud)
有解决方案吗
当我将弹性容器的高度设置为大于弹性项目所占据的高度时,包裹的项目之间会留有空间。请注意 - justify-content 和align-items 都设置为flex-start。这是片段(运行后单击整页)
.flex-container {
min-height: 100vh;
position: relative;
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: flex-start;
flex-wrap: wrap;
}
header,
main,
aside,
footer {
padding: 1rem;
background-color: tomato;
}
header,
footer {
width: 100%;
}
main {
width: 75%;
}
aside {
flex-grow: 1;
}Run Code Online (Sandbox Code Playgroud)
<div class="flex-container">
<header>Header Content</header>
<main>Main content here.</main>
<aside>Sidebar content</aside>
<footer>Footer Content</footer>
</div>Run Code Online (Sandbox Code Playgroud)
flex-direction: column;如果您反转所有属性,则可以重现这一点。这是预期的行为吗?如果是这样,为什么?有没有办法让我解决这个问题并得到类似的东西:
将 flex-container 高度设置为 100vh ?
以编程方式单击 li 元素“过去 30 天”(控制台)
<div class="ranges">
<ul>
<li>Today</li>
<li >Yesterday</li>
<li>Last 7 days</li>
<li>Last 30 days</li>
<li class="">This month</li>
<li>Custom Range</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
我尝试了很多方法但失败了
喜欢。
$('#Last 30 days').trigger('click');
$('#Last 30 days').click();
Run Code Online (Sandbox Code Playgroud)
我是 JavaScript 新手请帮帮我
我正在尝试value按 id 在数组中添加一个新的。我没有尝试在数组中添加新项目...为此我可以使用push(),但它添加新项目而不是新值。
我正在尝试这样做:
我的阵列:
const data =
[
{
"id": 1,
"year":2019,
"value": 2,
},
{
"id": 2,
"year": 2019,
"value": 89,
},
{
"id": 3,
"year": 2019,
"value": 99,
}
]
Run Code Online (Sandbox Code Playgroud)
在特定的内部id我会添加一个新值,如下所示:
data.forEach(item => {
if(item.id === 2){
//data inside id 2 -> item: 55
}
})
Run Code Online (Sandbox Code Playgroud)
所以我的新data数组如下所示:
const data =
[
{
"id": 1,
"year":2019,
"value": 2,
},
{
"id": 2,
"year": 2019,
"value": 89,
"item": 55
},
{ …Run Code Online (Sandbox Code Playgroud) 当我对小于256的数字执行24位移位时,得到否定结果吗?这是为什么?
console.log( (200<<23)>>23 );
console.log( (200<<24)>>24 ); // ???Run Code Online (Sandbox Code Playgroud)
这里的重点是确切的单词。这需要适用于任意数量的排列,因此希望我的例子很清楚。
给定一串随机字母,是否可以(使用RegEx)匹配给定字符串内的确切字母数量?
因此,如果我有一个str1包含字母的字符串(),ABZBABJDCDAZ并且想匹配字母JDBBAA(str2),则我的函数应该返回,true因为str1包含所有正确的字母足够多的时间了。然而,如果str1将被改变ABAJDCDA,那么该函数将返回false因为str2需要str1有至少2个字母的实例B。
这是我到目前为止使用的范围:
const findLetters = (str1, str2) => {
const regex = new RegExp(`[${str2}]`, 'g')
const result = (str1.match(regex))
console.log(result)
}
findLetters('ABZBABJDCDAZ', 'JDBBAA')Run Code Online (Sandbox Code Playgroud)
如您所见,它匹配正确的字母,但是匹配它们的所有实例。有什么方法可以使用RegEx做我想做的事情吗?我之所以在此关注RegEx的原因是,我需要高度优化此代码,到目前为止,我的其他函数都使用Array.every()和indexOf()太慢了。
注意:我的函数只需要返回一个true/false值。
我的角度应用程序我想下载 pdfBlob并对其进行处理以获取Uint8Array. 我想在服务中这样做,这将返回我 rxjsObservable<Uint8Array>但是我不能。我写下面的代码
public loadBinaryPDF(url): Observable<Uint8Array> {
return this.httpClient.get(url, { responseType: 'blob' }).pipe(map(async blob => {
let arrayBuff = await new Response(blob).arrayBuffer(); // some await here..
return new Uint8Array(arrayBuff);
}));
}
Run Code Online (Sandbox Code Playgroud)
但得到编译错误
ERROR in src/services/api-companies.service.ts(454,9): error TS2322:
Type 'Observable<Promise<Uint8Array>>' is not assignable to type 'Observable<Uint8Array>'.
Type 'Promise<Uint8Array>' is missing the following properties from type 'Uint8Array':
BYTES_PER_ELEMENT, buffer, byteLength, byteOffset, and 25 more.
Run Code Online (Sandbox Code Playgroud)
所以问题是我async-await在里面使用pipe/ map。如何解决?(我不想找到允许使用 async-await 并返回 …
我有以下代码(头部简化 - 未测试)
<div class="table">
<div *ngFor="let item of list" class="row">
{{ item.id }} {{ item.name }}
</div>
</div>
<button (click)="more = !more">{{ more ? 'less':'more' }}</button>
Run Code Online (Sandbox Code Playgroud)
我只想在开头显示前 3 个列表项 - 当用户单击“更多”时,我想显示所有列表项。怎么做?
javascript ×6
angular ×3
regex ×2
algorithm ×1
arrays ×1
axios ×1
children ×1
click ×1
components ×1
css ×1
flexbox ×1
google-maps ×1
html ×1
html-lists ×1
methods ×1
object ×1
parent ×1
react-native ×1
string ×1
typescript ×1