我有路由器
{
path: 'reset-password',
component: ResetPasswordComponent,
}
Run Code Online (Sandbox Code Playgroud)
并且我希望能够将其作为直接链接 ( /reset-password) 或使用传递的参数 ( /reset-password?uid=gsSxc&code=DsdxFSd)打开,因此在创建路由器快照时我想查看传递的参数。
我怎样才能做到这一点?我需要为此创建两个不同的路由器吗?
我有 Angular 反应式表单,其中每个输入都是一个单独的组件,它接收父表单为@Input(). 在这个组件中,我想订阅他的错误,并更改变量值,如果有一些错误。每个控件的错误不仅来自值变化,所以我无法检查模糊或值变化的错误。这样做的正确方法是什么?
表单.html
<form [formGroup]="formName">
<app-input-group [parentForm]="formName" [name]="controlName"></app-input-group>
</form>
Run Code Online (Sandbox Code Playgroud)
输入组.ts
export class InputGroupComponent {
@Input parentForm: FormGroup
@Input name: string
public status: string
// Need to call this function when control in form have errors
public getStatus() {
if (this.parentForm.get(this.name).errors) {
this.status = 'suspended'
} else {
this.status = 'boosted'
}
}
}
Run Code Online (Sandbox Code Playgroud) 我在 useEffect 钩子中有 fetch 方法:
export const CardDetails = () => {
const [ card, getCardDetails ] = useState();
const { id } = useParams();
useEffect(() => {
fetch(`http://localhost:3001/cards/${id}`)
.then((res) => res.json())
.then((data) => getCardDetails(data))
}, [id])
return (
<DetailsRow data={card} />
)
}
Run Code Online (Sandbox Code Playgroud)
但是在DetailsRow组件内部这个数据没有定义,这意味着我在获取数据之前渲染了这个组件。如何正确解决?
我有一个对象地图:
const myMap = new Map()
myMap.set(123, {
name: 'Lorem',
elements: {
books: ['book#1', 'book#2', 'book#3']
}
})
myMap.set(521, {
name: 'Ipsum',
elements: {
books: ['book#42', 'book#13', 'book#42']
}
})
Run Code Online (Sandbox Code Playgroud)
在某些时候,我需要在 Map 中找到一个元素,该元素包含book#42在elements.books数组中。我怎样才能正确地做到这一点?
我有带字符串的多维数组:
const arr = [['a', 'b'], ['c', 'd'], ['d', 'a']]
Run Code Online (Sandbox Code Playgroud)
如何记录控制台所有嵌套数组中超过1次的所有值?(对于此示例功能,应该使用console.log'a'和'd')。
谢谢您的帮助
在我的云功能中,我有下一个功能:
export const collectionOnUpdate = functions.firestore.document('cards/{id}').onUpdate(async (change, context) => {
await updateDocumentInAlgolia(change);
});
Run Code Online (Sandbox Code Playgroud)
每次编辑文档的任何字段时都会触发此功能。但我只想在特定字段之一更改时运行它(在本例中,例如:title, category),而不是在任何其他字段更改时运行它。
我怎样才能做到这一点?
我正在使用usePreviousValue自定义挂钩从我的组件获取以前的 props 值:
const usePreviousValue = value => {
const ref = useRef();
useEffect(() => {
ref.current = value;
});
return ref.current;
};
const MyComponent = ({ count }) => {
const prevCount = usePreviousValue(count)
return (<div> {count} | {prevCount}</div>)
}
Run Code Online (Sandbox Code Playgroud)
但在这种情况下,在渲染组件时prevCount我总是只有第一个prop 值,并且下一个更新的 prop 值永远不会分配给它。count有没有什么方法可以正确地将 nextProp 和 prevProp 与功能性 React 组件进行比较?
firebase google-cloud-datastore angularfire2 angular google-cloud-firestore
我有React组件,其中有一些动态文本:
...
let spanLength
return(
<SomeComp>
...
<span>Some static text: {someDynamicText}, {someAnotherText}</span>
...
</SomeComp>
)
Run Code Online (Sandbox Code Playgroud)
如何获取span元素内文本的长度作为spanLength变量?
我有SVG元素,我希望通过x和y轴对齐文本.
<svg width="90px" height="90px" viewBox="-9 -3 90 76" style="border: 1px solid black;">
<g>
<text>Lorem</text>
</g>
</svg>Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?谢谢你的任何提示.
PS我无法更改viewBox和SVG元素的大小或从g元素外移动文本.
javascript ×4
angular ×3
reactjs ×3
firebase ×2
react-hooks ×2
angularfire2 ×1
arrays ×1
css ×1
ecmascript-6 ×1
html ×1
router ×1
sorting ×1
svg ×1