我在AngularJS项目中使用基于jQuery的select2组件.我和这里的人有类似的问题:https://github.com/fronteed/icheck/issues/322,并使用那里的建议解决了它.准确地说,我TypeError: $(...).select2 is not a function在没有使用该建议时收到错误.
即我在Webpack的配置中添加了下一行@angular/cli/models/webpack-configs/common.js.
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
]
Run Code Online (Sandbox Code Playgroud)
它是在angular/cli中启用jQuery的最佳方法吗?
我不认为在https://github.com/angular/angular-cli/wiki/stories-global-lib中做同样的事情是正确的,因为
a)webpack捆绑jQuery而无需在脚本中指定它
b)TypeError: $(...).select2 is not a function当你按照故事中所描述的那样包含它时,它仍会抛出错误.
我的Angular应用程序突然没有调用ngOnInit(),router.navigation()这意味着我的组件无法正确加载.我认为这可能是由于我做出的一些改变,但恢复改变并没有解决问题.
正常导航导致组件无法正确加载的示例; 此页面由以下代码列表导航
this.router.navigate(['/result', this.params.data._id]);:
重新加载页面,组件正确加载:
以下是我的一些代码清单,
app.module.ts
@NgModule({
imports: [
BrowserModule,
FormsModule,
AppRoutingModule,
AgGridModule.withComponents(
[SampleResultButtonComponent]
),
ChartsModule
],
declarations: [
AppComponent,
LoginComponent,
LogoutComponent,
SignupComponent,
FilesComponent,
NavbarComponent,
ProfileComponent,
UploadComponent,
SampleGridApplicationComponent,
SampleResultButtonComponent,
AssetGridApplicationComponent,
ResultComponent,
ResetPasswordComponent,
AssetComponentDetailComponent
],
bootstrap: [ AppComponent ],
entryComponents: [AssetComponentDetailComponent]
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud)
APP-routing.module.ts
@Injectable()
export class NoAuthGuard implements CanActivate {
constructor(private router: Router) {}
canActivate() {
const activeUser = Kinvey.User.getActiveUser();
if (activeUser) {
return true;
}
// Navigate to the …Run Code Online (Sandbox Code Playgroud) 我正在为我的 angular 项目中的一个问题寻找解决方案,ng serve --watch但未检测到某些文件中的更改。
我得到了一个解决方案,上面写着使用 --poll=2000
它真的奏效了。
但是没有关于 flag poll功能的明确信息。
我们有一个 Angular 7 应用程序,我们使用 Angular CLI 进行构建,我们使用以下命令构建应用程序:
ng build --prod
我们已经检查过并将哈希值添加到文件名中。我们还使用以下内容设置了 index.html:
<meta http-equiv="Cache-control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
Run Code Online (Sandbox Code Playgroud)
尽管如此,我们仍然需要在发布后要求我们的用户按 ctrl+F5 来查看最新版本,看来 Chrome 正在缓存 index.html。
无论如何,有没有更好的方法来解决这个问题。我们正在考虑在每个版本中更改 index.html 文件以将当前日期和时间附加到名称和 angular.json 中,但我们更愿意使用提供的工具来解决这个问题。
任何帮助表示赞赏。
我正在按照angular 官方网站的说明将 angular 6 更新为 angular 7 。
在更新会话期间:
我输入了更新 v7 的 angular/cli 和核心的命令
$ ng update @angular/cli@v7 @angular/core@v7。
更新后我得到了Invalid rule result: Function().
这是命令提示符输出:
added 106 packages from 85 contributors, removed 5 packages, updated 5 packages, moved 1 package and audited 36489 packages in 39.604s
found 18 vulnerabilities (12 low, 1 moderate, 5 high)
run `npm audit fix` to fix them, or `npm audit` for details
Invalid rule result: Function().
Run Code Online (Sandbox Code Playgroud)
有谁知道我为什么收到消息?
这是package.json文件中的依赖项。
"dependencies": …Run Code Online (Sandbox Code Playgroud) 我使用 angular cli 命令ng new my-app创建了新的 angular 项目
然后,我想在目录中创建名为登陆页面的模块src/app,所以我使用命令ng gm登陆页面 --routing=true创建两个文件,即一个模块和一个路由文件,如下所示:
src/app/landing-page/landing-page-routing.module.ts (254 bytes)
src/app/landing-page/landing-page.module.ts (300 bytes)
Run Code Online (Sandbox Code Playgroud)
但是现在,我想用它的根组件创建模块并在名为登陆页面的单个文件夹中路由这两个模块,那么我如何使用单个 cli 命令来做到这一点?
我收到这个奇怪的警告
Locale data for 'en-US' cannot be found. No locale data will be included for this locale
跑步时 ng build --configuration=prod --localize
这是我的 angular.json
// omitted
"i18n": {
"sourceLocale": "en-US",
"locales": {
"sr-Latn": {
"translation": "src/locale/messages.sr.xlf",
"baseHref": "/sr/"
}
}
},
// omitted
Run Code Online (Sandbox Code Playgroud)
该文档明确说明默认情况下导入 en-US。更糟糕的是,当我将 sourceLocale 更改为任何其他语言(比如“de”)时,警告消息就会消失。
手动注册 en-US 区域设置数据也无济于事
我对“platformBrowserDynamic().bootstrapModule(app.app_module)”调用有问题,错误消息是“未捕获的错误:断言错误:传入的类型不是 NgModuleType,它没有 '?mod' 属性”。但是我可以在调试过程中看到这个属性: AppModule NgModule proto emod property
app.app_module 是一个新的 @NgModule 实例,用于引导我的自定义应用程序组件。我使用了打字稿。有没有人知道为什么会发生这种情况?
另外这里还有源 JS 代码https://gist.github.com/sunnygleason/74e84acd0a03a925ec901594723ce876 我正在将它转换成 Typescript Angular CLI 项目。这是 https://github.com/AnatoliYatskevich/WIA
我更改的特定文件是: https: //github.com/AnatoliYatskevich/WIA/blob/master/src/main.ts https://github.com/AnatoliYatskevich/WIA/blob/master/src/index.html https: //github.com/AnatoliYatskevich/WIA/blob/master/src/app/app.component.ts https://github.com/AnatoliYatskevich/WIA/blob/master/src/app/app.module.ts
工具 WebStorm,来自https://www.pubnub.com/docs/angular2-javascript/pubnub-javascript-sdk 的示例格式。
谢谢
我已将我的 .NET core 3.1+Angular 9.1 更新为 Angular 10.0.2,我使用的步骤:
ng update @angular/core @angular/cli之后 VS 2019 v 16.6.3 没有显示智能感知和验证,项目运行没有问题。如果我在 VS Code 中打开项目一切正常
我发现问题就在我跑完之后 ng update @angular/cli
将项目恢复到 9.1 一切正常
谢谢
visual-studio typescript angular-cli angular visual-studio-2019
我目前在 Angular 中遇到了非常奇怪的问题。一周前我在我的一个分支上工作,它很好并且构建正确。但我不知道它是如何在下面的“ng build”期间开始抱怨的,这是我今天不断遇到的错误:
node_modules/@types/babel__traverse/index.d.ts(1136,44): error TS1109: Expression expected.
node_modules/@types/babel__traverse/index.d.ts(1137,21): error TS1109: Expression expected.
node_modules/@types/babel__traverse/index.d.ts(1137,37): error TS1005: ';' expected.
node_modules/@types/babel__traverse/index.d.ts(1137,43): error TS1109: Expression expected.
node_modules/@types/babel__traverse/index.d.ts(1139,1): error TS1128: Declaration or statement expected.
Run Code Online (Sandbox Code Playgroud)
我尝试了以下选项来解决此问题,但没有取得任何成功:
选项 1 - 删除和安装 node_modules, 选项 2 - 删除和安装 @types/babel_traverse
任何人都可以让我知道可能是什么原因。这是我的本地 angular/dependancy 安装版本:
Angular CLI: 7.3.10
Node: 8.15.0
OS: win32 x64
Angular: 7.2.15
... animations, common, compiler, compiler-cli, core, elements
... forms, http, language-service, platform-browser
... platform-browser-dynamic, router, service-worker
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.13.10
@angular-devkit/build-angular 0.13.9
@angular-devkit/build-ng-packagr 0.13.9 …Run Code Online (Sandbox Code Playgroud) angular-cli ×10
angular ×8
javascript ×3
typescript ×3
angular5 ×1
angular6 ×1
angular9 ×1
build ×1
jquery ×1
ng-modules ×1
pubnub ×1