Tag: angular

Angular2 RC6:'<component>不是已知的元素'

在浏览器控制台中,当我尝试运行我的Angular 2 RC6应用程序时,出现以下错误: 错误:模板parsing错误:“标题区域”不是已知的元素:1.如果“标题区域”是一个angular度组件,则validation它是否是该模块的一部分。 2.如果'header-area'是一个Web组件,那么在这个组件的'@ NgModule.schema'中join“CUSTOM_ELEMENTS_SCHEMA”来抑制这个消息。 <div class="page-container"> [ERROR->]<header-area></header-area> <div class="container-fluid"> “):PlannerComponent @ 1:2 我不明白为什么没有find组件。 我的PlannerModule看起来像这样: @NgModule({ declarations: [ PlannerComponent, HeaderAreaComponent, NavbarAreaComponent, EreignisbarAreaComponent, GraphAreaComponent, nvD3 ], imports: [ RouterModule, CommonModule, ModalModule ], bootstrap: [PlannerComponent], }) export class PlannerModule {} 就我所了解的ng2模块的概念而言,模块的各个部分都是在“声明”中声明的。 为了完整起见,这里是PlannerComponent: @Component({ selector: 'planner', providers: [CalculationService], templateUrl: './planner.component.html', styleUrls: ['./planner.component.styl'] }) export default class PlannerComponent […]

toBe(true)vs toBeTruthy()vs toBeTrue()

expect(something).toBe(true) , expect(something).toBeTruthy()和expect(something).toBeTrue()什么expect(something).toBeTrue() ? 请注意, toBeTrue()是一个自定义匹配器,在jasmine-matchers toBeTrue() 器中引入了其他有用的方便的匹配器,如toHaveMethod()或toBeArrayOfStrings() 。 这个问题是泛泛而谈的,但是,作为一个真实世界的例子,我正在testing一个元素是在protractor显示的。 我应该在这种情况下使用哪个匹配器? expect(elm.isDisplayed()).toBe(true); expect(elm.isDisplayed()).toBeTruthy(); expect(elm.isDisplayed()).toBeTrue();

如何在Angular 2中的组件之间共享数据?

在Angular 1.xx中,您只需要提供相同的服务,最终得到相同的实例,从而可以共享服务中的数据。 现在在Angular 2中,我有一个组件可以参考我的服务。 我可以读取和修改服务中的数据,这很好。 当我尝试在另一个组件中注入相同的服务时,好像我得到一个新的实例。 我究竟做错了什么? 是模式本身是错误的(使用服务共享数据)还是我需要将服务标记为单例(在应用程序的一个实例中)或其他? 我在2.0.0-alpha.27/ btw 我通过@Component注释中的appInjector (edit:now providers )注入一个服务,然后在构造函数中保存一个引用。 它在组件本地工作 – 只是没有跨组件(他们不共享相同的服务实例),我想他们会。 更新 :从Angular 2.0.0开始,我们现在有了@ngModule,你可以在@ngModule上定义providers属性下的providers 。 这将确保将该服务的相同实例传递给该模块中的每个组件,服务等。 https://angular.io/docs/ts/latest/guide/ngmodule.html#providers

Angular 2快速入门:意外的令牌<

我试图根据在http://angular.iofind的quickstart设置angular2。 我已经完全按照指南中的描述复制每个文件,但是当我运行npm start并打开浏览器选项卡时,在控制台中出现以下错误消息:“正在加载…” Uncaught SyntaxError: Unexpected token < (program):1 __exec @ system.src.js:1374 Uncaught SyntaxError: Unexpected token < angular2-polyfills.js:138 Evaluating http://localhost:3000/app/boot Error loading http://localhost:3000/app/boot 这是我的app.component.ts : import {Component} from 'angular2/core'; @Component({ selector: 'my-app', template: `<h1>My First Angular 2 App</h1>` }) export class AppComponent { } 我的boot.ts : import {bootstrap} from 'angular2/platform/browser'; import {AppComponent} from './app.component'; bootstrap(AppComponent); […]

创buildPostgreSQL ROLE(用户),如果它不存在

如何编写一个SQL脚本来在PostgreSQL 9.1中创build一个ROLE,但是如果它已经存在则不会引发错误? 目前的脚本只有: CREATE ROLE my_user LOGIN PASSWORD 'my_password'; 如果用户已经存在,则失败。 我想要这样的东西: IF NOT EXISTS (SELECT * FROM pg_user WHERE username = 'my_user') BEGIN CREATE ROLE my_user LOGIN PASSWORD 'my_password'; END; …但这不起作用 – IF似乎不支持在普通的SQL。 我有一个batch file,创build一个PostgreSQL 9.1数据库,angular色和一些其他的东西。 它调用psql.exe,传入一个SQL脚本的名字来运行。 到目前为止,所有这些脚本都是普通的SQL,如果可能的话,我想避免使用PL / pgSQL等。

select器“my-app”与任何元素都不匹配

问题是当我运行我的应用程序,它工作正常。 但是,当我刷新它,大部分时间我得到下面的味精。 select器“my-app”与任何元素都不匹配 但奇怪的是,当我刷新我的应用程序很多次,它也可以。 所以最终我有一个奇怪的行为,我的应用程序,无法弄清楚这一点。 有时候它有时候不会… 任何build议,不能拿出代码? 注:我没有复杂的结构或组件,但实现简单。

Angular2如果在表单标签中使用ngModel,则必须设置name属性或表单

我收到来自Angular 2的这个错误 core.umd.js:5995 EXCEPTION: Uncaught (in promise): Error: Error in app/model_exposure_currencies/model_exposure_currencies.component.html:57:18 caused by: If ngModel is used within a form tag, either the name attribute must be set or the form control must be defined as 'standalone' in ngModelOptions. Example 1: <input [(ngModel)]="person.firstName" name="first"> Example 2: <input [(ngModel)]="person.firstName" [ngModelOptions]="{standalone: true}"> <td *ngFor="let lag of ce.lags"> […]

AngularJS自动同步服务器和客户端之间的数据

在AngularJS文档中有些东西我似乎无法find,或者我只是想念。 我在后端创build了一个带有NodeJS和Express的Web应用程序,我试图了解它如何在前端与Angular进行交互。 特别是,我将有一个用于Angular获取信息的JSON API。 我希望前端始终处于最新状态。 我的问题是: 双向数据绑定function是否意味着Angular($ resource或$ http)每n秒自动从服务器获取数据? 它自然使用长轮询,短轮询还是websocket? 你需要JQuery来实现服务器 – 客户端同步还是一切都可以用Angular来完成? 你是否需要添加额外的代码来使这种行为发生? 我需要使用$超时吗? 我似乎find的每个例子都涉及客户端获取数据一次。 不与服务器同步数据。

Angular2加载的文件请求过多

我正在使用Angular2制作一个网站,而且我有我想要的是一个问题。 在我的angular度页面的第一次加载时, SystemJS发出超过500个请求来检索angular2/src目录中的每个Angular2文件。 总的来说,首次下载量超过4MB,启动时间超过14秒。 我的index.html包含以下脚本: <script src="libs/angular2/bundles/angular2-polyfills.js"></script> <script src="libs/systemjs/dist/system.src.js"></script> <script src="libs/rxjs/bundles/Rx.js"></script> <script src="libs/angular2/bundles/angular2.min.js"></script> <script src="libs/angular2/bundles/http.dev.js"></script> <script src="libs/jquery/jquery.js"></script> <script src="libs/lodash/lodash.js"></script> <script src="libs/bootstrap/js/bootstrap.js"></script> 而我的systemJs初始化代码如下所示: <script> System.config({ defaultJSExtensions: true, paths: { '*': 'libs/*', 'app/*': 'app/*' }, packageConfigPaths: ['libs/*/package.json'], packages: { app: { format: 'register', defaultExtension: 'js' } } }); System.import('app/main') .then(null, console.error.bind(console)); </script> 我的公用文件夹具有以下结构: . ├── img ├── […]

AngularJS – 如何使用ng-repeat构造自定义filter,以有条件地返回项目

我有一个ng-repeat打印列表项目。 我想写一个自定义的filter,以便列表项将打印,只有当条件为真。 我似乎有错误的结构,因为它似乎variables没有通过filter。 的index.php <div ng-show="userDetails.username" class="nav"> <p>Menu</p> <li ng-repeat="menuItem in menu | matchAccessLevel:$rootScope.userDetails.accessLevel:menuItem.minAccess | orderBy:'position' "> <a ng-href="/angular-app/app/{{menuItem.id}}">{{menuItem.name}}</a> </li> </div> app.js userApp.filter('matchAccessLevel', function() { return function( item, userAccessLevel, minAccessLevel ) { if( userAccessLevel >= minAccessLevel ) { return item; } } });