小编Sha*_*rav的帖子

Angular2版本RC.6"指令"在@Component错误中

我正在使用Angular2并从官方网站下载了package.json.当我试图在@Component装饰器中使用"指令"时,我收到此错误.

我附上了我的代码错误:

[ts]
Argument of type '{ selector: string; template: string; directives: string; 
}' is not assignable to parameter of type 'ComponentMetadataType'.

Object literal may only specific known properties, and 'directives' does not
exist in type 'ComponentMetadataType'.
(property) directives: string
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

import { Component } from '@angular/core';
import { PeopleListComponent } from './people-list/people-list.component';

@Component({
 selector: 'my-app',
 template: '<h1>{{ title }}</h1>',
 directives: ''   //ERROR //NOT ABLE TO RECOGNIZE
})

export class AppComponent { 
  title = "My title";
} 
Run Code Online (Sandbox Code Playgroud)

这是我的package.json:

        {
          "name": …
Run Code Online (Sandbox Code Playgroud)

angularjs-directive angular2-template angular

21
推荐指数
2
解决办法
3万
查看次数

Angular 2自定义错误处理和路由器

我有一个自定义异常处理程序,如果发生任何异常(只是尝试它),它应该将用户带到自定义错误页面.

我试图使用Injector获取路由器的实例.这样做的原因,我相信注入器将给现有的路由器实例并使用它我将能够路由用户.

任何想法为什么这不起作用或如何实现这一点?

谢谢 :)

@Injectable()
export class AppExceptionHandler extends ExceptionHandler{

constructor(){
    super(null, null);
}

call(exception:any, stackTrace?:any, reason?:string):void {
    console.log('call...')


    var providers = Injector.resolve([ROUTER_PROVIDERS]);
    var injector = Injector.fromResolvedProviders(providers);

    // this is causing issue, not sure it is the correct way
    let router : Router = injector.get(Router);

    // not executed
    console.log(router)

    // not executed 
    console.log('done...')
    router.navigate(["CustomErrorPage"]);
    }

}
Run Code Online (Sandbox Code Playgroud)

答案 - 在2.0.0-beta.17中测试感谢Druxtan

1. Created a file app.injector.ts inside the app folder (app/app.injector.ts)
let appInjectorRef;

export const appInjector = (injector?) => { …
Run Code Online (Sandbox Code Playgroud)

angular

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

如何在Angular 2 CLI中使用"ng build --prod"和"ng serve --prod",获得404错误

当我尝试使用--prod选项运行ng build时,它会编译成一个main.js文件,并且我在控制台中没有错误.

但是当我在浏览器中运行应用程序时,它仍然会查找单个js文件.

我的主要内容:

// default
import { provide, enableProdMode, ExceptionHandler } from '@angular/core';
import { LocationStrategy, HashLocationStrategy } from '@angular/common';
import { bootstrap } from '@angular/platform-browser-dynamic';
import { HTTP_PROVIDERS, Http } from '@angular/http';

// External
import {
  TranslateService, TranslateLoader, TranslateStaticLoader
} from 'ng2-translate/ng2-translate';
import {Angulartics2} from 'angulartics2';

// mine
import { CustomExceptionHandler } from './app/_common/CustomExceptionHandler';
import { UserService } from './app/_services/user.service';
import { MessagesService } from './app/_services/messages.service';
import { APP_ROUTER_PROVIDERS } from './app/app.routes';
import { App, environment …
Run Code Online (Sandbox Code Playgroud)

javascript production-environment angular-cli angular

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

如何通过'role'属性选择元素并使用vanilla JS按类过滤?

标记:

<ul>
  <li role="presentation" class="active">
    <a href="#1" aria-controls="1" role="tab">How to Install for iPad</a>
  </li>
  <li role="presentation">
    <a href="#2" aria-controls="2" role="tab">How to Install for Mac</a>
  </li>
  <li role="presentation">
    <a href="#3" aria-controls="3" role="tab">How to Install for PC</a>
  </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

当我使用document.querySelectorAll('[role ="presentation"]'); 结果是数组 [li.active,li,li]

我如何删除.active类并使用普通JS w/o JQuery将其附加到这些li中的任何其他类更简单的方法?

javascript css-selectors

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

用这个javascript打开屏幕中心的新窗口?

我对javascript的体验非常有限.我想在屏幕中央打开新窗口.

<script type="text/javascript">
function fbs_click() {
var twtTitle = document.title;
var twtUrl = location.href;
var maxLength = 140 - (twtUrl.length + 1);
if (twtTitle.length > maxLength) {
    twtTitle = twtTitle.substr(0, (maxLength - 3)) + '...';
}
var twtLink = 'http://twitter.com/home?status=' + encodeURIComponent(twtTitle + ' ' + twtUrl);
window.open(twtLink,'','width=300,height=300'); } </script>
Run Code Online (Sandbox Code Playgroud)

如果有人可以请更新我的代码来完成一个中心的弹出窗口,这将是惊人的!

html javascript popup popupwindow

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