在我的 Angular 9 应用程序中,我有一个抽象类:
export abstract class MyAbstractComponent {
constructor(
protected readonly cd: ChangeDetectorRef,
) {
super();
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
和一个扩展它的组件:
@Component({
// ...
})
export class MyConcreteComponent extends MyAbstractComponent {
// ...
}
Run Code Online (Sandbox Code Playgroud)
一切正常,除了测试,我收到以下错误:
错误:此构造函数与 Angular 依赖注入不兼容,因为它在参数列表索引 0 处的依赖项无效。如果依赖类型是像字符串这样的原始类型,或者此类的祖先缺少 Angular 装饰器,就会发生这种情况。
请检查 1) 索引 0 处参数的类型是否正确,以及 2) 是否为此类及其祖先定义了正确的 Angular 装饰器。
typescript angular angular-test angular-ivy angular-dependency-injection
当我们想到template
在Angular2或Angular1.X 中使用时,我们知道下面是基本的写作方式之一:
template: './template-ninja.html'
使用Angular1.X,我们可以预先缓存所有模板,$templateCache.put()
如下所示:
var myApp = angular.module('Ninja', []);
myApp.run(function($templateCache) {
$templateCache.put('templateNinja.html', 'This is the content of the template-ninja');
});
Run Code Online (Sandbox Code Playgroud)
这将减少http请求的数量.我想知道如何使用Angular2实现相同的功能.有人可以帮忙吗?谢谢.
如何在Angular 2中使用此模块?任何例子?
到目前为止,我安装了模块并导入了Angular 2组件.
在发布之前,候选角度提供了捆绑文件.由于发布候选版本没有更多的捆绑文件.包括angular2和rxjs我的应用程序现在可以加载超过7秒的671个请求.这削弱了发展.
有谁知道如何捆绑angular和rxjs并将它们包含在system.config中?
我想在Apache服务器上部署Angular 2应用程序.我读过各种指南喜欢这个和这个,但他们没有工作.我已经npm
和ng
安装在服务器上.
简而言之,这就是我所做的:
npm install
.ng build --prod
命令,它创建了一个dist
目录.apache
root 更改为/var/www/html/dist
目录.mod_rewrite
,重新启动apache
并.htaccess
在我的dist
目录中添加它.<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
但是,只有我的主页domain.com
的作品,其他页面一样domain.com/login
,domain.com/register
等等抛出404错误.即使domain.com/index.html/login
不起作用.
该应用程序在我正在使用它开发它的本地系统上正常工作ng serve
.我错过了什么?
在我的Angular 4应用程序中,我有一个接受字符串输入的组件:
<app-my-component [myInput]="'some string value'"></app-my-component>
Run Code Online (Sandbox Code Playgroud)
在某些情况下,我需要在字符串中传递一个变量,例如:
<app-my-component [myInput]="'My name is ' + name + '!'"></app-my-component>
Run Code Online (Sandbox Code Playgroud)
如果我可以使用es6模板文字(也就是模板字符串或反向标记字符串)会很好:
<app-my-component [myInput]="`My name is ${name}!`"></app-my-component>
Run Code Online (Sandbox Code Playgroud)
但它不起作用:
未捕获错误:模板解析错误:分析器错误:意外的令牌Lexer错误:表达式中第1列的意外字符[`]
完成它的正确方法是什么?
javascript typescript ecmascript-6 template-literals angular
我已经走过了使用Angular2但编写ES5代码的道路,这意味着我找到的示例和指南通常必须从与TypeScript相关的答案中翻译出来.
有人可以帮助我使用ES5版本:
引导应用程序.在TypeScript中,我看到它完成为:
import {WORKER_APP_PLATFORM, WORKER_APP_APPLICATION} from "angular2/platform/worker_app";
import {platform} from "angular2/core";
platform([WORKER_APP_PLATFORM]).application([WORKER_APP_APPLICATION]).bootstrap(myApp)
Run Code Online (Sandbox Code Playgroud)
访问web_workers组件:
import {Component} from 'angular2/web_worker/worker';
@Component({ ... ])
Run Code Online (Sandbox Code Playgroud)
我假设后者将通过调用来实现
ng.web_worker.worker.Component({ ... })
Run Code Online (Sandbox Code Playgroud)
但似乎并非如此:ng.web_worker未定义.
问题可能是我似乎无法正确包含web_worker/ui.js.当我包含它而不是bundle/angular2-all.umd.js时,我只收到有关require undefined的错误消息.当我在我的项目中明确包含RequireJS时,我得到了许多其他错误.
任何帮助将不胜感激!
使用Angular 4,可以测试Component的模板,例如检查单击按钮是否触发了预期的方法和类似的东西.
但是如何将模板包含在测试范围内?默认情况下它们不是(使用Karma + Jasmine + Istanbul的Angular CLI测试).
在我的Angular 6应用中,我需要将Component作为其ng-template传递给另一个Component 。
原因是我有一个组件A,需要多次复制,但是每次它必须包含具有相同Inputs的不同组件(我们称它们为Component B和Component C)。
组件A模板:
<div class="row-detail-panel">
<h4 class="row-detail-panel-title">{{ newEntity ? 'Add new' : 'Edit this'}} {{ entityName }}</h4>
<!--THIS IS THE COMPONENT I WANT TO INJECT-->
<app-component-b
[inline]="true"
[form]="form"
></app-component-b>
<!--END-->
<!--some more html code here-->
</div>
Run Code Online (Sandbox Code Playgroud)
我使用以下方法创建一个Component A实例:
<app-component-a
[entity]="row"
[entityName]="entityName"
></app-component-a>
Run Code Online (Sandbox Code Playgroud)
所以我考虑使用ng-template
,因此按如下所示更改Component A模板:
<div class="row-detail-panel">
<h4 class="row-detail-panel-title">{{ newEntity ? 'Add new' : 'Edit this'}} {{ entityName }}</h4>
<ng-template></ng-template> …
Run Code Online (Sandbox Code Playgroud) 我尝试了多种使用Brew在 macOS 中安装 Google Chrome Canary 的方法
brew install chrome-canary
错误:未找到类似名称的公式。错误:没有可用的配方或名称为“chrome-canary”的桶。
brew install --cask google-chrome-canary
错误:木桶“google-chrome-canary”不可用:不存在具有此名称的木桶。
brew cask install google-chrome-canary
错误:调用brew cask install被禁用!使用brew install [--cask] 代替。
他们都失败了。如何使用最新brew
版本在最新的 macOS 中安装 Google Chrome Canary?
angular ×9
typescript ×4
javascript ×2
.htaccess ×1
angular-dependency-injection ×1
angular-ivy ×1
angular-test ×1
apache ×1
bundle ×1
ecmascript-6 ×1
homebrew ×1
istanbul ×1
jasmine ×1
karma-runner ×1
macos ×1
ng-template ×1
rxjs ×1
systemjs ×1