Tag: angular

Angular 2路由器没有基地href设置

我收到错误,找不到原因。 这是错误: EXCEPTION: Error during instantiation of LocationStrategy! (RouterOutlet -> Router -> Location -> LocationStrategy). angular2.dev.js:23514 EXCEPTION: Error during instantiation of LocationStrategy! (RouterOutlet -> Router -> Location -> LocationStrategy).BrowserDomAdapter.logError @ angular2.dev.js:23514BrowserDomAdapter.logGroup @ angular2.dev.js:23525ExceptionHandler.call @ angular2.dev.js:1145(anonymous function) @ angular2.dev.js:14801NgZone._notifyOnError @ angular2.dev.js:5796collection_1.StringMapWrapper.merge.onError @ angular2.dev.js:5700run @ angular2-polyfills.js:141(anonymous function) @ angular2.dev.js:5719zoneBoundFn @ angular2-polyfills.js:111lib$es6$promise$$internal$$tryCatch @ angular2-polyfills.js:1511lib$es6$promise$$internal$$invokeCallback @ angular2-polyfills.js:1523lib$es6$promise$$internal$$publish @ angular2-polyfills.js:1494(anonymous […]

expression式___在检查后发生了变化

为什么在这个简单的组成部分 @Component({ selector: 'my-app', template: `<div>I'm {{message}} </div>`, }) export class App { message:string = 'loading :('; ngAfterViewInit() { this.updateMessage(); } updateMessage(){ this.message = 'all done loading :)' } } 投掷: EXCEPTION:检查后,expression式“我在App @ 0:5中{{message}}”已被更改。 上一个值:'我正在加载:('。当前值:'我都加载完成了:)'[我是{{message}}在App @ 0:5] 当我所做的是更新一个简单的绑定,当我的观点开始?

如何dynamic创build引导模式作为Angular2组件?

原始标题 :无法在Angular 2中初始化dynamic附加(HTML)组件 我创build了一个指令,在初始化时将模态添加到主体。 当一个button(注入了指令)被点击时,这个模式启动。 但我希望这个模式的内容是另一个组件(事实上,我希望模态是组件)。 看来我无法初始化组件。 这是我所做的一件事: http://plnkr.co/edit/vEFCnVjGvMiJqb2Meprr?p=preview 我试图让我的组件模板 '<div class="modal-body" #theBody>' + '<my-comp></my-comp>' + '</div>

关注新添加的input元素

我有一个新的Angular 2应用程序与input框列表。 当用户点击返回键时,我在他们正在编辑的那个之后立即添加一个新的input框。 或者说,我(asynchronous)向模型中的数组添加一个新条目,这将导致Angular 2在不久的将来自动生成一个新的input框。 我怎样才能使input焦点自动改变到新添加的元素? 或者,我得到一个引起DOM生成的模型对象的引用。 从组件代码中,有没有一种方法来search代表特定模型对象的DOM元素? 这是我的代码,只是使这个工作。 希望这对于一些Angular 2开发者来说足够让人反感:-) app.WordComponent = ng.core .Component({ selector: 'word-editor', template:'<input type="text" [value]="word.word" (input)="word.update($event.target.value)" (keydown)="keydown($event)"/>', styles:[ '' ], properties:[ 'list:list', 'word:word' ] }) .Class({ constructor:[ function() { } ], keydown:function(e) { if(e.which == 13) { var ul = e.target.parentNode.parentNode.parentNode; var childCount = ul.childNodes.length; this.list.addWord("").then(function(word) { var interval = […]

Angular2 – 错误如果不检查是否存在{{object.field}}

我有一个关于检查对象中是否存在字段的问题。 我想打印所有类别的用户,所以我正在做这样的事情: <ul *ngIf="user.categories.length > 0" *ngFor="#category of user.categories"> <li> {{category.name}} </li> </ul> 原因? 所有的数据正确打印,但我在Web控制台中出现错误,如: Cannot read property 'name' of null 但是当我做这样的事情时: <ul *ngIf="user.categories.length > 0" *ngFor="#category of user.categories"> <li *ngIf="category"> {{category.name}} </li> </ul> 那么一切都好。 我做错了什么,或者我每次都要检查一下? 你有过这样的问题吗? 提前致谢。

Angular2 – 为每个请求设置标题

我需要在用户login后为每个后续请求设置一些授权标头。 信息: 要为特定请求设置标题, import {Headers} from 'angular2/http'; var headers = new Headers(); headers.append(headerName, value); // HTTP POST using these headers this.http.post(url, data, { headers: headers }) // do something with the response 参考 但以这种方式为每个请求手动设置请求标头是不可行的。 如何在用户login后设置标题集,并在注销时删除这些标题?

如何在AngularJS中取消$ http请求?

在AngularJS中给定一个Ajax请求 $http.get("/backend/").success(callback); 如果发起另一个请求(相同的后端,例如不同的参数),取消该请求最有效的方法是什么。

Angular ng-repeat错误“不允许在中继器中复制。

我正在定义一个自定义filter如下所示: <div class="idea item" ng-repeat="item in items" isoatom> <div class="section comment clearfix" ng-repeat="comment in item.comments | range:1:2"> …. </div> </div> 正如你所看到的ng-repeat所使用的filter嵌套在另一个ng-repeat中 filter是这样定义的: myapp.filter('range', function() { return function(input, min, max) { min = parseInt(min); //Make string input int max = parseInt(max); for (var i=min; i<max; i++) input.push(i); return input; }; }); 我越来越: 错误:不允许在中继器中复制。 中继器:在item.comments中评论 范围:1:2 ngRepeatAction […]

* ngIf和* ngFor在相同的元素上导致错误

我在试图在同一个元素上使用Angular的*ngFor和*ngIf时遇到了问题。 当试图遍历*ngFor中的集合时,集合被视为null ,因此在尝试访问模板中的属性时失败。 @Component({ selector: 'shell', template: ` <h3>Shell</h3><button (click)="toggle()">Toggle!</button> <div *ngIf="show" *ngFor="let thing of stuff"> {{log(thing)}} <span>{{thing.name}}</span> </div> ` }) export class ShellComponent implements OnInit { public stuff:any[] = []; public show:boolean = false; constructor() {} ngOnInit() { this.stuff = [ { name: 'abc', id: 1 }, { name: 'huo', id: 2 }, { […]

Angular 2 HTTP GET与TypeScript错误http.get(…).map不是中的函数

我在Angular 2遇到了HTTP问题。 我只想GET一个JSON列表并在视图中显示它。 服务类 import {Injectable} from "angular2/core"; import {Hall} from "./hall"; import {Http} from "angular2/http"; @Injectable() export class HallService { public http:Http; public static PATH:string = 'app/backend/' constructor(http:Http) { this.http=http; } getHalls() { return this.http.get(HallService.PATH + 'hall.json').map((res:Response) => res.json()); } } 在HallListComponent我从服务中调用getHalls方法: export class HallListComponent implements OnInit { public halls:Hall[]; public _selectedId:number; constructor(private _router:Router, […]