我在Angular项目中遇到一个错误,该错误最终通过将代码包装到
this.zone.run(() => {/* my code here */});
Run Code Online (Sandbox Code Playgroud)
如该答案所述。
我以前的理解zone
是angular无法检测到异步callbacks
第三方库所做的更改,因为“它们不在angular的范围内zone
”。如果我单击a button
,则触发的事件不是浏览器的本机click
事件,而是click
由angular创建的自定义(修补)事件,其handler
在zone
so angular中的运行会意识到其回调处理程序所做的更改。
但是我无法理解通过router.navigate()
在第三方回调中运行来创建此问题(如此 github问题所示)。是不是Router
一个service
角本身?为什么zone
在第三方中调用时,它不会自动通知angular callback
?
我通过router.navigate
在NGXS的状态缩减器中使用来解决此问题。
我的问题是:
有人可以解释我到底什么时候需要包装我的代码NgZone
?
调试了几个小时,意识到我的代码没有zone
上下文,这很烦人。
我希望 的内容.main
限制为 5 行,超过该行时,我想显示省略号。
.main {
width: 100px;
margin-bottom: 6px;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 5;
-webkit-box-orient: vertical;
}
Run Code Online (Sandbox Code Playgroud)
<div class="main">
<ul>
<li>hello1</li>
<li>hello2</li>
<li>hello3</li>
<li>hello4</li>
<ul>
<li>hello5</li>
<li>hello6</li>
<li>hello7</li>
<li>hello8</li>
</ul>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
这在 Chrome 中按预期工作,内容在第 5 行后以省略号结束。但在 Safari 中,最终没有显示省略号。此外,Safari 显示 6 行而不是 5 行。请参阅下面的屏幕截图。
有人对如何在 Safari 中修复它有任何建议吗?
版本:
Chrome:版本 85.0.4183.121(官方版本)(64 位)
Safari:版本 13.1.2
我ObjectIds
在 mongoDB 中有一个字符串数组 ( )。我想切换该数组中的一个元素:如果该元素存在于数组中,则将其删除,否则推送该元素。
例子:
arr = ["5b608c0769698c3990c64ef3","5b608c0769698c3990c64ef4"]
element = ["5b608c0769698c3990c64ef3"]
Run Code Online (Sandbox Code Playgroud)
最终数组:
arr = ["5b608c0769698c3990c64ef4"]
Run Code Online (Sandbox Code Playgroud)
我的用例:
我正在创建一个博客网站,并在博客架构中存储每个喜欢该博客的用户的 ID,以便在向用户显示博客时突出显示喜欢按钮。
如果它有一个活动的类,我想设置我的组件的样式.但它不起作用.
thread.component.html
<div>thread works!</div>
Run Code Online (Sandbox Code Playgroud)
thread.component.css
:host .active {
display: block;
border: 1px solid white;
}
Run Code Online (Sandbox Code Playgroud)
app.component.html
<app-thread class="active"></app-thread>
Run Code Online (Sandbox Code Playgroud)
thread.component.html
<div>thread works!</div>
Run Code Online (Sandbox Code Playgroud)
thread.component.css
:host {
display: block;
border: 1px solid white;
}
Run Code Online (Sandbox Code Playgroud)
app.component.html
<app-thread></app-thread>
Run Code Online (Sandbox Code Playgroud) 以下是我的Angular 5应用程序的简化版本。我有一个reducer,我想在我的根模块中注册它。在LINE A中,我收到以下错误消息:
ERROR in src/app/store/app.reducers.ts(7,14): error TS2322: Type '{ post: (state: State, action: Action) => void; }' is not assignable to type 'ActionReducerMap<AppState, Action>'.
Types of property 'post' are incompatible.
Type '(state: State, action: Action) => void' is not assignable to type 'ActionReducer<State, Action>'.
Type 'void' is not assignable to type 'State'.
Run Code Online (Sandbox Code Playgroud)
app.module.ts:根模块
imports: [
...
StoreModule.forRoot(reducers)
],
Run Code Online (Sandbox Code Playgroud)
store / app.reducers.ts:在全球商店内
import {ActionReducerMap} from "@ngrx/store";
import * as fromPost from "../postDir/store/post.reducers";
export interface AppState { …
Run Code Online (Sandbox Code Playgroud) 我有一个AWS EC2
在云中运行的 Ubuntu 实例AWS
,在我的 Windows 计算机中,我使用 PuTTy 来连接它。这种方式的问题是,我只有一个终端 CLI 来访问/编辑EC2
实例中的所有代码,其中包含许多文件和文件夹。
有没有办法可以连接到AWS EC2
我的 Windows 计算机并访问 IDE 中的代码?比如远程桌面连接之类的?
注意:我无法在本地计算机上测试我的代码,因为我要访问的服务仅将我的AWS EC2
IP 列入白名单。
有没有办法让destructure
对象的属性名称中包含连字符。我花了一段SyntexError
时间这样做(这是合理的,因为 JS 不允许变量名带有 a hyphen
)。
let human= {
"first-name":"John",
"last-name":"Doe",
age:150
}
let {age}= human;
// let {"first-name"}= human;//error
// let {first-name}= human;//error
console.log(age)
Run Code Online (Sandbox Code Playgroud)
无论是否打开开发工具,Chrome控制台始终会保留日志.我想要相同的网络选项卡.
即使没有打开开发人员工具,是否可以在Chrome中记录XHR请求?如果没有,是否可以在其他浏览器中使用?
注意:我正在寻找反应形式方法的解决方案。模板驱动表单的解决方案已经在这里
我有一个具有反应式表单的库,我正在尝试使用 ng-template 和 ng-container (A 行)插入表单输入。
库组件
html
<form [formGroup]="mainForm">
<input type="text" formControlName="inside">
<ng-container [ngTemplateOutlet]="template"></ng-container> //line A
</form>
Run Code Online (Sandbox Code Playgroud)
TS:
export class LibraryComponent implements OnInit {
@Input() template;
mainForm: FormGroup;
constructor(private formBuilder: FormBuilder) { }
ngOnInit() {
this.mainForm = this.formBuilder.group({
inside: ['inside'],
outside: ['outside'],
});
}
}
Run Code Online (Sandbox Code Playgroud)
应用组件
<app-library [template]="outer"></app-library>
<ng-template #outer>
<input type="text" formControlName="outside">
</ng-template>
Run Code Online (Sandbox Code Playgroud)
这样做时我收到错误:
preview-d2335ca5bdb955611c1cb.js:1 ERROR Error: formControlName must be used with a parent formGroup directive. You'll want to add a formGroup
directive and …
Run Code Online (Sandbox Code Playgroud) 我是Web开发的初学者,并且遵循Michael Hartl撰写的Ruby on Rails教程.我使用命令更新了我的rails gem install rails -v 3.2.3
,它似乎工作.但是当我使用命令检查rails版本时rails -v
,它仍然显示了一些不同的版本:Rails 4.2.5.2
.我重新开始我的终端但没有运气.请你帮助我好吗.
提前致谢
angular ×4
javascript ×2
ajax ×1
amazon-ec2 ×1
css ×1
html ×1
mongodb ×1
ngrx ×1
ngrx-store ×1
ngzone ×1
ruby ×1
typescript ×1