对于想了解无法使用画布读取null的属性“getContext”的读者,本文将是一篇不可错过的文章,我们将详细介绍无法使用画笔工具,因为此图层的内容不能直接编辑,并且为您提供关于android–无法读
对于想了解无法使用画布读取null的属性“ getContext”的读者,本文将是一篇不可错过的文章,我们将详细介绍无法使用画笔工具,因为此图层的内容不能直接编辑,并且为您提供关于android – 无法读取null的属性’documentElement’、Angular 2无法读取null的属性’config’、Angular FormArray-无法读取null的属性“ push”、angular – 无法使用ViewContainerRef读取未定义的属性“createComponent”的有价值信息。
本文目录一览:- 无法使用画布读取null的属性“ getContext”(无法使用画笔工具,因为此图层的内容不能直接编辑)
- android – 无法读取null的属性’documentElement’
- Angular 2无法读取null的属性’config’
- Angular FormArray-无法读取null的属性“ push”
- angular – 无法使用ViewContainerRef读取未定义的属性“createComponent”
无法使用画布读取null的属性“ getContext”(无法使用画笔工具,因为此图层的内容不能直接编辑)
我收到错误消息Uncaught TypeError: Cannot read property ''getContext'' of null
,文件中的重要部分在…我想知道,因为game.js在下面的目录中,所以找不到画布?我该怎么办?
./index.html:
<canvas id="canvas" width="640" height="480"></canvas>
./javascript/game.js:
var Grid = function(width, height) { ... this.draw = function() { var canvas = document.getElementById("canvas"); if(canvas.getContext) { var context = canvas.getContext("2d"); for(var i = 0; i < width; i++) { for(var j = 0; j < height; j++) { if(isLive(i, j)) { context.fill; } else { context.fill; } context.fillRect(i*15, j*15, 14, 14); } } } }}
答案1
小编典典我想问题是您的js在加载html之前运行。
如果使用的是jquery,则可以使用文档就绪函数包装代码:
$(function() { var Grid = function(width, height) { // codes... }});
或者只是将您的js放在
android – 无法读取null的属性’documentElement’
01-13 23:49:52.219: E/Web Console(529): Uncaught TypeError: Cannot read property ‘documentElement’ of null at file:///android_asset/www/soapclient.js:158
这是相关代码:
var ns = (wsdl.documentElement.attributes["targetNamespace"] + "" == "undefined") ? wsdl.documentElement.attributes.getNamedItem("targetNamespace").nodeValue : wsdl.documentElement.attributes["targetNamespace"].value;
解决方法
所以要么你必须把它包括在你的heades中
Accept: Access-Control-Allow-Origin
或者也使用
chrome.exe --disable-web-security
或者您也可以安装chrome扩展
Enable cors request extention in chrome
希望它会有所帮助.
Angular 2无法读取null的属性’config’
$ng serve Cannot read property 'config' of null TypeError: Cannot read property 'config' of null at Class.run (C:\Users\damien\Desktop\application\node_modules\@angul ar\cli\tasks\serve.js:22:63) at check_port_1.checkPort.then.port (C:\Users\damien\Desktop\application\node_modules\@angular\cli\commands\serve.js:103:26) at process._tickCallback (internal/process/next_tick.js:103:7)
我重新安装了CLI,其他任何工作都没有.我可能是json文件的东西?
Angular FormArray-无法读取null的属性“ push”
由于嵌套了formArray,因此必须按如下所示更改模板。
component.html
<ng-container
formArrayName="formArray"
*ngFor="let forArr of form.get('formArray').controls; let x = index"
>
<ng-container [formGroupName]="x">
<div
formArrayName="credentials"
*ngFor="
let creds of forArr.controls.credentials?.controls;
let i = index
"
>
<ng-container [formGroupName]="i">
<input placeholder="Username" formControlName="username" />
<input placeholder="Password" formControlName="password" />
</ng-container>
</div>
</ng-container>
</ng-container>
component.ts
addCreds() {
const formArray = this.form.get("formArray") as FormArray;
(formArray.controls[0].get("credentials") as FormArray).push(
this.fb.group({
username: "",password: ""
})
);
}
Forked Example
angular – 无法使用ViewContainerRef读取未定义的属性“createComponent”
Cannot read property ‘createComponent’ of undefined
在我试图注入的ReferenceTableComponent组件上我有
@Component({ selector: 'app-reference-table',templateUrl: './refTable.component.html',styleUrls: ['./refTable.component.scss'] }) export class ReferenceTableComponent implements OnInit { observable: Observable<any>; @ViewChild('selectorTarget',{read: ViewContainerRef}) selectorTarget; // colors @input() public datas: Array<string>; public availableColors: Array<string>; @input() public nextRow: Array<string>; //tailles @input() public headList: Array<string>; public rows: Array<any> = [{}]; public rowIDs: Array<any> = []; constructor(private _cr: ComponentFactoryResolver,private _viewContainerRef: ViewContainerRef) { } ngOnInit() { this.computeAvailableColors(); } addRow() { console.log('this.availableColors 2: ',this.availableColors) this.rows.push({}); } computeAvailableColors() { this.availableColors = _.concat([''],this.datas); this.rowIDs = _.map(this.rows,'color') this.availableColors = _.difference(this.availableColors,this.rowIDs); const select: ComponentRef<SelectOptionsComponent> = this.selectorTarget.createComponent( this._cr.resolveComponentFactory(SelectOptionsComponent) ); select.instance.availableColors = this.availableColors; select.instance.row = this.rows[0]; }
在我的组件html上
<td onSelectColor($event) #selectorTarget> </td>
我试图注入的组件
@Component({ selector: 'kia-select-options',template: `<div><select [(ngModel)]="row.color" (ngModelChange)="sendColorEvent(row,$event)"> // value is a string or number <option *ngFor="let obj of availableColors">{{obj}}</option> </select></div>` }) export class SelectOptionsComponent { // couleurs @input() public availableColors: Array<string>; @input() public row: {}; public color: string; @Output() public changed = new EventEmitter(); constructor(private injector: Injector) { } sendColorEvent(row,color) { console.log(event) this.changed.emit({ color: color,row: row }); } }
知道ReferenceTableComponent它是从父组件使用动态地自我填充,并且它工作正常
@ViewChild('target',{read: ViewContainerRef}) target; const factory = this.componentFactoryResolver.resolveComponentFactory(ReferenceTableComponent); const ref = this.target.createComponent(factory);
解决方法
ngAfterViewInit() { this.computeAvailableColors(); }
我们今天的关于无法使用画布读取null的属性“ getContext”和无法使用画笔工具,因为此图层的内容不能直接编辑的分享就到这里,谢谢您的阅读,如果想了解更多关于android – 无法读取null的属性’documentElement’、Angular 2无法读取null的属性’config’、Angular FormArray-无法读取null的属性“ push”、angular – 无法使用ViewContainerRef读取未定义的属性“createComponent”的相关信息,可以在本站进行搜索。
本文标签: