小编San*_*oud的帖子

角延迟加载:路由到特定要素组件

我正在尝试实现有角度的6延迟加载,我想在我的主页面中建立一个链接,将每个链接指向一个特定的要素组件。

我项目的层次结构如下:

app.module.ts
|__homepage.component.ts
|__options.component.ts
|__feature.module.ts
   |__buy.component.ts
   |__sell.component.ts
Run Code Online (Sandbox Code Playgroud)

从中homepage.component,用户可能可以直接访问buy.componentsell.component

homepage.component为了实现此目的,应该如何构造路线或链接?

从下面的代码中您可以注意到,我的延迟加载路线仅指向模块,但''默认情况下触发的路线并不总是用户要访问的路线(如果他/她点击了“出售” “,他想查看“销售”的销售组件,反之亦然),并且我想避免为每个模块创建子主页...

这是我到目前为止的路线代码:

应用程序路由

const routes: Routes = [
  {
    path: '',
    redirectTo: '/home',
    pathMatch: 'full'
  },
  {
    path: 'home',
    component: HomeComponent
  },
  {
    path: 'options',
    component: OptionsComponent
  },
  {
    path: 'buy',
    loadChildren: "../app/posts/feature.module#FeatureModule"
  },
  {
    path: 'sell',
    loadChildren: "../app/posts/feature.module#FeatureModule"
  }
];
Run Code Online (Sandbox Code Playgroud)

feature.routing.ts

{
    path: '',
    redirectTo: '/buy',
    pathMatch: 'full'
  },
  {
    path: 'buy',
    component: BuyComponent
  },
  {
    path: …
Run Code Online (Sandbox Code Playgroud)

typescript angular

5
推荐指数
2
解决办法
902
查看次数

通过实体类名动态获取 DbSet<T>

我正在尝试使用它的名称动态System.Reflections获取DbSet<T>

我现在有的是:

  • DbSet
  • 所述DbSetType存储在可变

在尝试使用该dbcontext.Set<T>()方法时,我面临的问题出现了,因为(这些是我迄今为止的尝试):

  • 当我尝试分配给<T>my 时DbSet Type,它会引发以下编译错误:

    “XXX 是一个变量,但像类型一样使用”

  • 如果我尝试使用两种Extension方法,您将在我的代码下面找到(我为了设法弄一本制作IQueryable<T>),它返回一个IQueryable<object>,不幸的是不是我期待的,因为当然,当我尝试用进一步的反射操作它,它缺少原始类具有的所有属性......

我究竟做错了什么?我怎样才能得到一个DbSet<T>

我的代码如下,当然,如果您需要更多信息、说明或代码片段,请告诉我。

我的控制器的方法

public bool MyMethod (string t, int id, string jsonupdate)
{
    string _tableName = t;
    Type _type = TypeFinder.FindType(_tableName); //returns the correct type

    //FIRST TRY
    //throws error: "_type is a variable but is used like a type"
    var tableSet = _context.Set<_type>();  

    //SECOND …
Run Code Online (Sandbox Code Playgroud)

c# system.reflection entity-framework-core asp.net-core

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

每 X 秒调用一个函数

有没有办法在 Angular 2+ 中每 X 秒或几分钟触发一次函数?

例如,如果我想每 60 秒myService.refreshloginStatus()从 main 中启动一个函数app.component怎么办?

我发现这个问题在互联网上搜索,但我不知道它是否也适用于此以及如何在 Angular 中实现它......有人可以在 Angular 中为我提供这个的具体用法吗?

PS:如果您认为这个问题可能是链接问题的重复,请在评论中告诉我,我必须将其删除

typescript angular

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

从 OnActionExecuting 访问方法的属性

我想知道如何检查控制器方法是否具有特定属性,例如AllowAnonymous内部OnActionExecuting覆盖方法。

我尝试过这个:

var methodAttr = Attribute.GetCustomAttribute(context.ActionDescriptor.GetType(), typeof(AuthorizeAttribute));
Run Code Online (Sandbox Code Playgroud)

但我总是得到一个空值。

也尝试过这个:

MethodBase method = MethodBase.GetCurrentMethod();
AuthorizeAttribute methodAttr = (AuthorizeAttribute)method.GetCustomAttributes(typeof(AuthorizeAttribute), true)[0];
Run Code Online (Sandbox Code Playgroud)

但是,当没有 AuthorizeAttribute 时,我会收到超出范围的异常。

我怎样才能进行这项检查?

c# asp.net-mvc-filters .net-core

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

Webpack错误:angular_compiler_plugin - 无法读取未定义的属性"environment"

我正在尝试部署我的应用程序,但是当它执行命令时:

webpack.js --config webpack.config.vendor.js --env.prod
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

angular_compiler_plugin.ts:580 compiler.hooks.environment.tap('angular-compiler',()=> {
                                                                            ^
TypeError:无法读取未定义的属性'environment'

我已经用AngularCompilerPlugin替换了AoTPlugin,正如本文 "Tweaks"部分所建议的那样- 我已经为我的所有第一个应用程序创建所遵循 - 因为AotCaused我同样的错误,因为它的角度5不兼容但现在我有了这个错误,我真的迷失了解决它.

有谁知道如何解决这个问题?


我的代码如下

这是我的webpack.config.js内容:

const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin;
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
var nodeExternals = require('webpack-node-externals');

module.exports = (env) => {
    // Configuration in common to both client-side and server-side bundles
    const isDevBuild = !(env && env.prod);
    const sharedConfig = {

        stats: { modules: false },
        context: __dirname,
        resolve: { extensions: [ …
Run Code Online (Sandbox Code Playgroud)

webpack angular

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