这是在Sidenav的角度材质中使用的代码示例.我在我的页面上使用这个相同的例子.但是,我可以找到任何说明如何从屏幕右侧从左到右打开sidenav.谁知道怎么样?
<mat-sidenav-container class="example-container">
<mat-sidenav #sidenav mode="side" [(opened)]="opened" (opened)="events.push('open!')"
(closed)="events.push('close!')">
Sidenav content
</mat-sidenav>
<mat-sidenav-content>
<p><mat-checkbox [(ngModel)]="opened">sidenav.opened</mat-checkbox></p>
<p><button mat-button (click)="sidenav.toggle()">sidenav.toggle()</button></p>
<p>Events:</p>
<div class="example-events">
<div *ngFor="let e of events">{{e}}</div>
</div>
</mat-sidenav-content>
</mat-sidenav-container>
Run Code Online (Sandbox Code Playgroud)
我已经实现了一个CustomDateAdapter,如下所述:https : //medium.com/@esanjiv/working-with-custom-dateadapter-for-angular-material-2-datepicker-76d4446277dc
现在,我正在进行Angular Material 6迁移,并且出现以下错误
core.js:1598 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'TRIDENT' of undefined
TypeError: Cannot read property 'TRIDENT' of undefined
at CustomDateAdapter.NativeDateAdapter [as constructor] (core.es5.js:792)
at new CustomDateAdapter (custom-date-adapter.ts:21)
at _createClass (core.js:9262)
...
Run Code Online (Sandbox Code Playgroud)
core.es5.js第792行是这样的:
_this.useUtcForDisplay = !platform.TRIDENT;
Run Code Online (Sandbox Code Playgroud)
似乎平台未定义。
我注意到NativeDateAdapter的构造函数已在材料6中进行了更改,它还需要一个平台作为输入。
constructor(matDateLocale: string, platform: Platform);
Run Code Online (Sandbox Code Playgroud)
我缺少什么?如何在Angular Material 6中实现CustomDateAdapter?
假设我具有以下组件:
@Component({
selector: 'todo-lib',
template: `
<li *ngFor="let todo of libService.todos">
<div class="view">
<label>{{todo.title}}</label>
<ng-container *ngTemplateOutlet="incomingTemplate;context:ctx"></ng-container>
</div>
</li>
<ng-template #incomingTemplate let-service="templateService">
<button (click)="service.removeTodo(todo)">delete</button>
</ng-template>
`,
styles: []
})
export class TodoLibComponent implements OnInit {
ctx = {
templateService: this.libService
};
Run Code Online (Sandbox Code Playgroud)
待办事项列表在libService内部。我不会在这里发布它,因为它的逻辑无关紧要。“ ng-template”将从另一个组件中注入,并将删除按钮添加到我的待办事项列表中。这意味着:通常没有删除选项,除了将提供“ ng-template”
但是,此方法将失败,并出现以下错误:
message: "_v.context.todo is undefined"
Run Code Online (Sandbox Code Playgroud)
由于“ todo”不是上下文对象“ ctx”的一部分,因此无法访问它。为了实现这一点,我将被迫这样做:
<ng-container *ngTemplateOutlet="incomingTemplate;context:{ todo: todo}">
Run Code Online (Sandbox Code Playgroud)
这将允许我访问待办事项对象,但不再访问服务。
看来我无法同时访问ngFor AND和在ctx属性中定义的服务定义的todo属性。是否有解决方案来实现两者?
干杯
我正在实现socketjs。但是我遇到了以下错误。
import * as SockJS from 'sockjs-client';
import * as Stomp from 'stompjs/lib/stomp.js';
Run Code Online (Sandbox Code Playgroud)
提前致谢。
这是我的角度代码-
import * as Socket from 'socket.io-client';
import * as Stomp from 'stompjs/lib/stomp.js';
initializeWebSocketConnection2(){
let ws = new Socket(this.serverUrl);
this.stompClient = Stomp.over(ws);
let that = this;
this.stompClient.connect({}, function(frame) {
that.stompClient.subscribe("/test", function(message){
if(message.body) {
console.log(message.body);
window.location.reload();
}
});
that.stompClient.subscribe("/operation", function(message){
if(message.body) {
console.log(message.body);
window.location.reload();
}
});
Run Code Online (Sandbox Code Playgroud)
});
}
尝试升级到Angular 6并在index.html中引用以下内容时出现以下错误:
拒绝从' https:// localhost:44394 /〜/ assets / primengcss / themes / omega // theme.css ' 应用样式,因为它的MIME类型('text / html')不是受支持的样式表MIME类型,并且严格MIME检查已启用。
我正在使用角度6
我的HTML是
<form [formGroup]="myForm" >
<label>
<input type="text" formControlName="name" placeholder="name" required autofocus >
</label>
<label>
<select name="drop" formControlName="drop">
<option value="developer"selected >developer</option>
<option value="designer">designer</option>
<option value="admin">admin</option>
</select>
</label>
</form>
Run Code Online (Sandbox Code Playgroud)
即使我selected在option页面首次加载时在“开发人员”中进行设置,也未选择“开发人员”。我想这是一个小角度的错误,无法正确呈现html,因此我在定义表单时放入了组件:
myForm = this.formBuilder.group({
name:['',Validators.required],
drop:['developer']
});
Run Code Online (Sandbox Code Playgroud)
而且有效。
真正奇怪的是,当我this.myForm.reset();在另一个位于窗体外部的按钮内执行操作时,“名称”应为空,但下拉列表也完全为空,只是空白,但应显示“ developer”,对吗?
该按钮隐藏了一些元素,应该重置表单,它在表单外部并且确实
getOtherData(id){
this.myForm.reset();
Run Code Online (Sandbox Code Playgroud)
这行不通,所以我必须做
this.myForm.setValue({
name: '',
drop: 'developer'
});
Run Code Online (Sandbox Code Playgroud)
为了实际重置表格。这是怎么错的select用组合reset?我想使用reset一次并完全重置表单,而不会出现“ hacks”,该怎么办?
谢谢
我按照更新将我的角度5项目更新为角度6
npm install --save-dev @angular/cli@latest
ng update @angular/cli
ng update @angular/core
ng update @angular/material
ng update rxjs
Run Code Online (Sandbox Code Playgroud)
但是当运行ng服务时,错误会不断出现,如下所示
找不到本地工作区文件('angular.json')
我被告知.angular-cli.json被一个新的替换:angular.json,但架构不再是旧版本,
这是我当前的angular-cli.json,我怎么能改成angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "ngx-admin-demo"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico",
"favicon.png",
{
"glob": "**/*",
"input": "../node_modules/leaflet/dist/images",
"output": "./assets/img/markers"
}
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.css",
"./app/@theme/styles/styles.scss",
"../node_modules/primeng/resources/themes/omega/theme.css",
"../node_modules/primeng/resources/primeng.min.css",
"styles.scss"
],
"scripts": [
"../node_modules/pace-js/pace.min.js",
"../node_modules/echarts/dist/echarts.min.js",
"../node_modules/chart.js/dist/Chart.min.js",
"../src/assets/paho-mqtt.js"
],
"environmentSource": "environments/environment.ts",
"environments": …Run Code Online (Sandbox Code Playgroud) 我有一个用Angular6编写的复杂计算器应用程序,该应用程序基于ngModelChange事件中的多个输入来计算结果,并直接在图表中显示这些结果。计算是在服务器端完成的。现在,我想添加一个反跳时间,这样服务器在按下每个键时都不会收到请求。
我在ngModelChange中触发的计算方法如下所示:
async calculate(){
if(this.checkInputs()){
try{
let returnDto = await this.webApiService.calculate(new CalculatorInputDto(this.model)).toPromise();
this.outputCalculate.emit(returnDto);
}
catch(e){
console.log(e);
}
}
Run Code Online (Sandbox Code Playgroud)
而我的服务方式:
calculate(dto: CalculatorInputDto): Observable<any> {
let url = this.baseUrl + "calculate";
return this.http.post(url, JSON.stringify(dto), this.options)
.pipe(
debounceTime(5000),
map((res => res.json())),
catchError(error => this.handleError(error))
);
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我已经在我的服务中尝试了debounceTime(5000),但似乎没有任何改变。
有谁知道我该如何解决这个问题?
问题
我已经使用ngrx fromEvent运算符从2个输入文本字段中创建了一个Observable,我已经使用document作为目标了,但是现在我只想定位一个输入字段。我不确定使用什么代替文档来仅将一个输入字段作为目标。
到目前为止我为达成目标所做的一切
码
import { Component } from '@angular/core';
import { fromEvent } from 'rxjs';
@Component({
selector: 'my-app',
template: `<input type="text">
<input type="text">`
})
export class AppComponent {
ngOnInit() {
fromEvent(document, 'keyup')
.subscribe(res => console.log(res.target.value));
}
}
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助。
不幸的是,关于这个库的信息很少。安装后我还不太清楚我需要将哪些内容导入到app.module.ts中,以及是否有要导入的内容?我在index.html中规定了以下代码:
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\\(','\\)']]
}
});
</script>
<script type="text/javascript" async
src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?
config=TeX-MML-AM_CHTML'>
</script>
Run Code Online (Sandbox Code Playgroud)
如果我没有简单的文本,但是在某些列中出现带有公式的文本的表,该如何应用MathJax?也许您可以以某种方式将整个表转移到MathJax.Hub.Queue?
angular6 ×10
angular ×7
rxjs ×2
typescript ×2
css ×1
debouncing ×1
forms ×1
html ×1
mathjax ×1
ngfor ×1
reference ×1
rxjs6 ×1
spring-boot ×1
styles ×1