小编Ash*_*Jha的帖子

如何将角度端口从4200更改为任何其他角度端口

我想用5000而不是4200 ..

我试过的是我在根名称上创建了一个文件,ember-cli并根据下面的代码放置了JSON:

{
   "port": 5000
}
Run Code Online (Sandbox Code Playgroud)

但我的应用程序仍然运行4200而不是5000

angular-cli

191
推荐指数
17
解决办法
26万
查看次数

包“@angular/core”不是依赖项。同时将 Angular 8 更新为 Angular 9

将 Angular 8 项目更新为 Angular 9 时,出现错误

\n
\xe2\x9c\x94 Package successfully installed.\nUsing package manager: 'npm'\nCollecting installed dependencies...\nFound 0 dependencies.\nPackage '@angular/core' is not a dependency.\n
Run Code Online (Sandbox Code Playgroud)\n

我使用的命令

\n
ng update @angular/core@9 @angular/cli@9 --force\n
Run Code Online (Sandbox Code Playgroud)\n

npm angular-cli angular angular8 angular9

27
推荐指数
1
解决办法
2万
查看次数

Angular cli更新后获取错误

我的angular-cli版本是beta.16

我尝试通过以下命令更新

npm uninstall -g angular-cli @angular/cli
npm cache clean
npm install -g @angular/cli@latest
Run Code Online (Sandbox Code Playgroud)

在我尝试运行任何ng命令后成功安装

ng version 
ng help
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误

ng help
/usr/local/lib/node_modules/@angular/cli/models/config/config.js:15
    constructor(_configPath, schema, configJson, fallbacks = []) {
                                                           ^

SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/@angular/cli/models/config.js:2:18)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
Run Code Online (Sandbox Code Playgroud)

angular-cli

22
推荐指数
1
解决办法
1万
查看次数

"value == var"与"var == value"

在许多地方,我见过开发人员进行value == var比较,如下所示:

if ('https' === location.protocol) {
   port = 8443;
   protocol = 'wss://';
   isSecure = true;
}
Run Code Online (Sandbox Code Playgroud)

我知道那a == b是一样的b == a,为什么人们用value == var而不是var == value

这有标准吗?如果是的话,哪种标准方式?

javascript if-statement

7
推荐指数
1
解决办法
176
查看次数

何时在 Node js 中使用 eventEmitter?

我正在学习 Node js 中的新概念,即事件,但我找不到应该在哪里使用它,我想要任何真实的场景,但我找不到任何关于此的文章或博客。

var events = require('events');
var eventEmitter = new events.EventEmitter();

//Create an event handler:
var myEventHandler = function () {
  console.log('I hear a scream!');
}

//Assign the event handler to an event:
eventEmitter.on('scream', myEventHandler);
eventEmitter.on('test', function(){
    console.log("Testing event");
});

//Fire the 'scream' event:
eventEmitter.emit('scream');
eventEmitter.emit('scream');
eventEmitter.emit('test');
Run Code Online (Sandbox Code Playgroud)

我可以通过简单的调用函数来实现同样的事情,比如myEvenHandler()

javascript events node.js eventemitter

6
推荐指数
1
解决办法
3647
查看次数

如何在 Angular 2 中通过守卫向没有权限的用户显示消息

我正在使用 Angular 2 防护(canActivate)进行授权,但是如果用户转到他没有授权的路线,则会出现空白屏幕。

我想显示一条消息,表明您没有权限,这样怎么可能?

警卫服务:

import { Injectable } from '@angular/core';
import { CanDeactivate , CanActivate } from "@angular/router";

@Injectable()
export class LoginGuardService implements CanActivate,CanDeactivate<any>{

  constructor() { }

  canActivate(){    
    return true;
  }

  canDeactivate(){
    return window.confirm("You have unsaved changes. Still want to leave?");
   }

}
Run Code Online (Sandbox Code Playgroud)

路由文件

{path:'grade-listing' , component:GradeListingComponent ,canActivate:[LoginGuardService]},
Run Code Online (Sandbox Code Playgroud)

angular

5
推荐指数
1
解决办法
3826
查看次数

如何在保护角2中获取请求网址

如何在警卫服务中获取请求网址

HasPermissionService

@Injectable()
export class HasPermissionService implements CanActivate{
  private permissions = [];

  constructor(private _core:CoreService,private route1:Router, private _route:ActivatedRoute ,private route: ActivatedRouteSnapshot,private  state: RouterStateSnapshot) { 
    console.log('constructor calling ...');
    // console.log(this.route.url);
    this.permissions = this._core.getPermission();
    console.log('inside guard');
    console.log(this.permissions);
  }

  canActivate( ) {
    console.log(this.route);
    console.log(this._route);
    return true;
  }
}
Run Code Online (Sandbox Code Playgroud)

但是我正在变老,我来自哪里.如何获取当前网址?

路线

{path:'grade-listing',component:GradeListingComponent,canActivate:[HasPermissionService]}
Run Code Online (Sandbox Code Playgroud)

我需要获得'等级列表'

angular

5
推荐指数
1
解决办法
3749
查看次数

如何在javascript中从多个数组中获取单个数组

我有这样的数组

   var arr = [
                [ {"c": 1},{"d": 2} ],
                [ {"c": 2},{"d": 3} ]
             ]
Run Code Online (Sandbox Code Playgroud)

我想改成(仅限javascript)

var newArr  = [{"c": 1},{"d": 2},{"c": 2},{"d": 3}]
Run Code Online (Sandbox Code Playgroud)

我已经通过地图尝试了这个但没有获得预期的输出.

javascript

3
推荐指数
1
解决办法
1421
查看次数

如何使用无服务器部署功能,使其仅包含所需的文件夹/文件

    |--serverless.yml
    |--lib/
    |--node_modules/
    |--api/
        |--manageclient/
            |--addClient/
                |--handler.js
Run Code Online (Sandbox Code Playgroud)

这是我的文件夹结构,如何使用无服务器部署函数,使其仅包含 handler.js 和 node_modules/ 和 lib/。

您能否指定要在主 serverless.yml 上写入的功能命令?

我的YML函数声明

handler: api/manageclient/addClient/addclient.addclient
   package:
     exclude:
       - ./*
       - !api/manageclient/addClient/**
       - !api/node_modules/**
       - !api/lib/**
Run Code Online (Sandbox Code Playgroud)

javascript amazon-web-services aws-sdk aws-lambda serverless-framework

3
推荐指数
1
解决办法
8823
查看次数

为什么导入OnInit很重要

无需导入OnInit和实现

ngOnInit(){
  this.recipies=this.recipeService.getRecipies();
} 
Run Code Online (Sandbox Code Playgroud)

这仍然工作正常没有任何抱怨所以我为什么要使用像:

import { Component,EventEmitter,Output , OnInit } from '@angular/core';

export class RecipiesListComponent implements OnInit{}
Run Code Online (Sandbox Code Playgroud)

angular

2
推荐指数
1
解决办法
2536
查看次数