小编Twi*_*her的帖子

Angular 7 - 没有用于未指定名称属性的表单控件的值访问器

我的 Angular 7 应用程序出现此错误,但我不知道为什么。即使有一些研究,这个错误似乎也没有意义。

这就是我所拥有的:

<mat-form-field>
     <input matInput placeholder="Name" name="name" [(ngModel)]="data.name" [disabled]="inputReadonly" ngDefaultControl > 
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)

我已经尝试在 mat-form-field 和/或输入上使用和不使用 ngDefaultControl,使用和不使用 name 属性,并在输入时移动 [(ngModel)]。什么都没有改变,我仍然收到同样的错误。

html javascript angular

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

Angular Universal 不适用于 Angular Google Maps

技术:Angular Cli、Angular version 7、Angular Google Maps、Firebase Functions。

问题:我正在尝试为我的 angular 通用应用程序提供服务,但在构建时遇到 angular google maps 错误。

我得到的错误

/Users/test/Public/Leisure/leisure-app/functions/node_modules/@agm/core/services/managers/info-window-manager.js:1
(function (exports, require, module, __filename, __dirname) { import {
Observable } from 'rxjs';
                                                              ^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
Run Code Online (Sandbox Code Playgroud)

似乎 Angular Universal 不喜欢第三方库。

我关注的资源: https : //hackernoon.com/deploying-angular-universal-v6-with-firebase-c86381ddd445

我的应用模块:

import { AgmCoreModule } from '@agm/core';
import { AngularFireAuthModule } from '@angular/fire/auth';
import { AngularFireDatabase } from '@angular/fire/database';
import { AngularFireModule } from '@angular/fire';
import { ServiceWorkerModule …
Run Code Online (Sandbox Code Playgroud)

firebase angular-google-maps google-cloud-functions angular-universal angular

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

如何将 FormControl 从模板传递给函数?

假设我有这个:

<input formControlName="someName" (click)="onClick()">
Run Code Online (Sandbox Code Playgroud)

我希望我的onClick函数是通用的,并设置相应的值FormControl(我单击的函数)。

我如何将相关内容FormControl作为 的参数传递onClick

我以为我可以从FormControlDirectiveFormControlNamecontrol的属性中检索它,但它们都没有属性。exportAs

javascript angular angular-reactive-forms

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

如何通过ctrl复制事件,在FullCalendar v5中拖放 - 仅限纯javascript

我想仅CTRL + Drag & Drop使用PURE JavaScript在 FullCalendar v5 中实现。

我对主题进行了研究,发现这是在 FC github 上作为新功能 UI 请求进行讨论的。很少有建议如何做到这一点,即使是可行的建议。

arshaw 发表于 2015 年 8 月 19 日

You can use eventDrop to create this feature. jsEvent has a ctrlKey
on which you can test. Copy the event, received as a parameter, in a new variable.
revertFunc to make go back, and then apply renderEvent with the new variable created.
Run Code Online (Sandbox Code Playgroud)

chris-verclytte 发布于 2016 年 4 月 11 日 …

javascript fullcalendar fullcalendar-5

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

如何有条件地禁用客户端

我有一个服务器端呈现的应用程序(有过渡),我有一个404页面,我已经放入一个懒惰的模块(所以我不增加加载的Javascript大小).

这工作正常,但是当客户端接管时有一些闪烁,我认为这是由于主块完成加载后的JS块加载.

鉴于此页面只包含静态链接和一个routerLink,根本不需要客户端,我想知道是否有办法在某些URL上禁用客户端

编辑:正如评论中建议的那样,我试图有条件地引导应用程序.我不能将URL用作条件,因为服务器对不存在的URL响应404(此时没有重定向).因此,最适合使用的是TransferState我在服务器端成功设置的东西,它在结束body标记之前生成一些输出.

不幸的是我没有找到任何方法来正确实例化TransferState,main.ts因为它应该通过导入BrowserTransferStateModule,我看不到在main.ts文件中导入Angular模块的可能方法.

我试图直接用initTransferState函数实例化它,但似乎它不是设计在模块外部使用,因为我收到一个错误:

ERROR in ./src/main.ts
Module not found: Error: Can't resolve '@angular/platform-browser/src/browser/transfer_state' in 'G:\Documents\Projets\Myapp\Sources\master\frontend\src'
Run Code Online (Sandbox Code Playgroud)

除了做一些肮脏的反序列化之外的任何想法?

express angular-universal angular

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

“路由器”类型上不存在属性“导航”。您指的是“导航”吗?

我不知道为什么,但它突然停止工作......这import是正确的,但它看不到navigate()方法......有什么想法吗?
每个答案都与缺失有关,import但这里有一个正确的答案importnavigate()我的代码的每个部分都停止工作了,哈哈,这只是这里的例子。有任何想法吗?

import { Injectable } from '@angular/core';

import { Actions, Effect, ofType } from '@ngrx/effects';
import * as  AuthActions from './auth.actions'
import * as UserDetailsActions from '../user/user-store/user.actions';
import * as StudentActions from '../../student/student-store/student.actions';

import { map, mergeMap, switchMap, switchMapTo, concatMapTo, withLatestFrom } from 'rxjs/operators';

import { Router } from '@angular/router';

@Injectable()
export class AuthEffects {
    constructor(private actions$: Actions,
                private router: Router) { }

    @Effect()
    authSignin = this.actions$
        .pipe(
            ofType(AuthActions.TRY_SIGNIN), …
Run Code Online (Sandbox Code Playgroud)

javascript routes angular2-routing angular

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

如何将带有链接的表格复制到剪贴板以将其粘贴到 excel 中

我在网站上创建数据,就像表格一样。我想将该数据复制到excel。我使用 Tabs 转到行中的下一个单元格并使用换行符转到下一行:

let clipboard = 'My link' + "\t" + secondCell + "\t" + thirdCell + "\n" + 
firstCellSecondRow + "\t" + secondCellSecondRow + "\t" + thirdCellSecondRow;
navigator.clipboard.writeText(clipboard);
Run Code Online (Sandbox Code Playgroud)

将该文本复制到 Excel 表格中效果很好:

excel中的数据

现在我的挑战是,我想添加一个链接到一个单元格的文本。我的直觉方法是将以下文本添加到剪贴板:

let clipboard = '<a href="https://www.my-url.com">My link</a>' + "\t" + secondCell + "\t" + thirdCell + "\n" + 
firstCellSecondRow + "\t" + secondCellSecondRow + "\t" + thirdCellSecondRow;
navigator.clipboard.writeText(clipboard);
Run Code Online (Sandbox Code Playgroud)

但这不起作用,它实际上会显示带有 html 的文本:

excel中的数据

我想要的只是文本“我的链接”和一个可点击的实际链接:

excel中的数据

由于可以在 excel 中复制带有链接的文本,我觉得它应该以某种方式起作用。我可以用 javascript 做到这一点吗?

html javascript excel clipboard

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

如何正确序列化查询参数?

为了检索当前的查询参数,我使用这个:

import { useLocation } from 'react-router-dom';

function useQuery() {
    return new URLSearchParams(useLocation().search);
}
Run Code Online (Sandbox Code Playgroud)

然后在功能组件中:

const query = useQuery();
Run Code Online (Sandbox Code Playgroud)

Link但是,除了具有新值的查询参数之外,我没有找到任何集成的解决方案可以轻松设置为相同的查询参数。

到目前为止,这是我的解决方案:

const filterLink = query => param => value => {
  const clone = new URLSearchParams(query.toString());
  clone.set(param, value);
  return `?${clone.toString()}`;
}

return (
  <>
    <Link to={filterLink(query)('some-filter')('false')}>False</Link>
    <Link to={filterLink(query)('some-filter')('true')}>True</Link>
  </>
)
Run Code Online (Sandbox Code Playgroud)

我必须克隆该query对象,以免改变原始对象,并且filterLink在 JSX 中多次调用时不会产生不需要的副作用。我还必须自己添加问号,因为URLSearchParams.prototype.toString()不添加它。

我想知道为什么我必须自己这样做?我真的不喜欢在使用框架时做如此低级的事情。我错过了反应路由器中的某些东西吗?是否有更常见的做法可以满足我的需要?

javascript reactjs react-router react-router-dom

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

Redis 存储库和多态性不能一起工作

我有这个代码:

@Getter
@Setter
@RedisHash
class Root {
  private Base base;
}

public interface Base {

}

@Getter
@Setter
public class Implementor implements Base {
  // ...
}

public class CustomKeyspaceConfiguration extends KeyspaceConfiguration {
    private final String prefix;
    
    public SagtKeyspaceConfiguration(String prefix) {
        super();
        
        this.prefix = prefix;
    }
    
    @Override
    public boolean hasSettingsFor(Class<?> type) {
        if (super.hasSettingsFor(type) == false) {
            KeyspaceSettings settings = new KeyspaceSettings(type, prefix + ClassUtils.getUserClass(type).getName());
            addKeyspaceSettings(settings);
        }
        
        return true;
    }
}
Run Code Online (Sandbox Code Playgroud)

我有一个CrudRepositoryforRoot类,它允许我在 Redis 中成功存储该类型的对象。

但是当我使用 simple …

java spring redis spring-data

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

使用 Angular 9 构建库失败

我正在尝试将此库https://github.com/flauc/angular2-notifications从 Angular 2+迁移到 Angular 9。

最初的错误是关于ModuleWithProviders已经成为泛型类型的,所以我修复了它。我也在这里描述了一个错误https://github.com/angular/angular/issues/32352我修复了它require('@angular/compiler-cli');,现在我面临另一个错误:

../node_modules/@angular/common/common.d.ts:115:22 - 错误 NG6002:出现在 SimpleNotificationsModule 的 NgModule.imports 中,但无法解析为 NgModule 类

我很难理解发生了什么,因为我以前从未构建过库,并且使用 gulp 构建似乎有点 hacky,因为这一行ngc = require('@angular/compiler-cli/src/main').main引用了一个不属于公共 API 的函数。

编辑:

按照评论中的想法(以及我自己的感觉),我尝试在没有吞咽的情况下进行构建:

  • 创建了一个angular.json文件
  • 分离index.tspublic_api.tssimple-notifications.module.ts
  • 对文件和文件夹结构做了一些更改

但我仍然有同样的确切错误......

我的尝试:https : //github.com/youkouleley/angular2-notifications 我尝试用 构建它ng build,其中的脚本package.json尚未更新

gulp angular angular-library angular-ivy angular9

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