我究竟做错了什么?
app.component.ts
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
template: `{{title}}`
})
export class App {
title = "Angular 2 beta";
constructor() { console.clear(); }
}
Run Code Online (Sandbox Code Playgroud)
main.ts
import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app.component';
bootstrap(AppComponent);
Run Code Online (Sandbox Code Playgroud)
错误是
EXCEPTION: TypeError: Cannot read property 'annotations' of undefined
Run Code Online (Sandbox Code Playgroud) 假设我习惯于在服务器端编码(使用服务器端语言),现在我正在学习AngularJS.这意味着我首先需要对JavaScript有一个很好的理解.
如果我现在没有时间完全学习JavaScript,你会推荐五个JavaScript概念我先学习/好好成为一个有效的AngularJS开发人员吗?
如何在子组件观察到输入变化时调用父组件的功能?
以下是HTML结构.
# app.comopnent.html
<form>
<textbox>
<input type="text">
</textbox>
</form>
# textbox.component.html
<div class="textbox-wrapper">
<ng-content>
</div>
Run Code Online (Sandbox Code Playgroud)
限制如下.
ng-content并且需要将input元素投影到它.input元素输入时,在TextboxComponent中发出一个事件.input元素具有更多属性,例如<input type="text" (input)="event()">.我正在编写代码,但无法找到解决方案......
# input.directive.ts
@Directive({ selector: 'input', ... })
export class InputDirective {
ngOnChanges(): void {
// ngOnChanges() can observe only properties defined from @Input Decorator...
}
}
# textbox.component.ts
@Component({ selector: 'textbox', ... })
export class TextboxComponent {
@ContentChildren(InputDirective) inputs: QueryList<InputDirective>;
ngAfterContentInit(): void {
this.inputs.changes.subscribe((): void => { …Run Code Online (Sandbox Code Playgroud) 我的路由定义为/ abc /:id/xyz
其中abc /:id解析为ComponentA,而/ xyz是路由器插座中显示的子组件(ComponentB)
当导航到/ abc /:id/xyz时,当我在ComponentA中执行this.route.params.subscribe(...)(其中route是ActivatedRoute)时,我看到:id.在ComponentB中做同样的事情我没有看到:id.我猜ActivatedRoute正在使用url段.
无论如何要获得路线中的所有参数?
我<video>在Angular2组件中有一个HTML5 元素.我需要访问它以便在允许用户将其共享到Twitter之前检查持续时间.
有没有办法通过模型绑定或直接访问DOM,我可以在组件的支持类中获取此信息?
我尝试使用ng-model绑定它,就像在组件的模板中一样:
<video controls width="250" [(ng-model)]="videoElement">
<source [src]="video" type="video/mp4" />
</video>
Run Code Online (Sandbox Code Playgroud)
并在组件的类(TypeScript)中:
videoElement: HTMLVideoElement;
Run Code Online (Sandbox Code Playgroud)
这给了我这个错误: EXCEPTION: No value accessor for '' in [null]
我只是通过给视频元素一个id并使用document.getElementById("videoElementId")它来访问它,但似乎必须有更好的方法.
我想创建一个目录树,并且无论级别如何都可以访问所有项目,但是当我动态添加二级子级时,@ ViewChildren/@ViewQuery的QueryList不会更新:
import {bootstrap} from 'angular2/platform/browser';
import {Component, View, QueryList,ViewQuery, Query,ViewChildren} from 'angular2/core';
@Component({
selector: 'item',
})
@View({
template: `
<button (click)="addChild()">Add Child</button>
<ng-content></ng-content>
<div *ngFor="#child of children; #i = index">
<item> {{child.name}}</item>
</div>
`
})
export class Item {
//public children = [ { name: 'Child 1', age: 22 } ];
public children = [];
addChild() {
this.children.push({ name: 'Child' + (this.children.length + 1), age: 18 });
}
}
@Component({
selector: 'my-app'
})
@View({
directives: [Item],
template: `
<button …Run Code Online (Sandbox Code Playgroud) 我正在尝试将包含(click)事件的字符串注入Angular2模板.在加载DOM之后,很多字符串是从后端动态检索的.毫不奇怪Angular不会识别注入的(click)事件.
示例模板:
<div [innerHTML]="test"></div>
Run Code Online (Sandbox Code Playgroud)
后端给出的示例字符串:
var test = "When ready, <span (click)=\"itemClick($event)\">click me</span>."
Run Code Online (Sandbox Code Playgroud)
Angular组件中的函数调用示例:
itemClick(event) {
debugger;
}
Run Code Online (Sandbox Code Playgroud)
var test = "When ready, <span onClick=\"itemClick($event)\">click me</span>."
Run Code Online (Sandbox Code Playgroud)
果然,我得到一个错误itemClick is not defined,所以我知道它正在寻找那个javascript函数.
所以问题:我怎样才能让Angular2订阅这个事件或函数?
我将 Spark 与 python 一起使用。上传 csv 文件后,我需要解析 csv 文件中的一列,其中包含 22 位数字长的数字。为了解析该列,我使用了LongType()。我使用 map() 函数来定义列。以下是我在 pyspark 中的命令。
>>> test=sc.textFile("test.csv")
>>> header=test.first()
>>> schemaString = header.replace('"','')
>>> testfields = [StructField(field_name, StringType(), True) for field_name in schemaString.split(',')]
>>> testfields[5].dataType = LongType()
>>> testschema = StructType(testfields)
>>> testHeader = test.filter(lambda l: "test_date" in l)
>>> testNoHeader = test.subtract(testHeader)
>>> test_temp = testNoHeader.map(lambda k: k.split(",")).map(lambda
p:(p[0],p[1],p[2],p[3],p[4],***float(p[5].strip('"'))***,p[6],p[7]))
>>> test_temp.top(2)
Run Code Online (Sandbox Code Playgroud)
注意:我还尝试在变量test_temp中使用“long”和“bigint”代替“float” ,但 Spark 中的错误是“找不到关键字”,以下是输出
[('2012-03-14', '7', '1698.00', 'XYZ02abc008793060653', 'II93', ***8.27370028700801e+21*** , 'W0W0000000000007', '879870080088815007'), ('2002-03-14', '1', …Run Code Online (Sandbox Code Playgroud) 首先,我应该提一下我正在努力过渡到客户端编程.我对js很新.我以前的经验主要是在C和一些装配.几年前我还做了一些非常简单的PHP,当时它还是4.0.所以简而言之,是javascript的新手,但我还是把它放了一下.
我做了很多搜索和潜伏,但未能纠正我的问题.
我正在弄清楚AngularJS的一些基础知识并且它非常好,但我很难理解指令的工作方式以及如何从自定义控件访问数据.
长话短说我试图使用angularjs为bootstrap工作制作一个自定义控件,这样我就可以在表单中正确使用它.
这是控件:http://tarruda.github.com/bootstrap-datetimepicker/
我有一些其他的控件,我想要工作,但我想如果我可以得到这一个我可以很容易得到其他人.
这是我在这一点上的基本框架的链接:http://jsfiddle.net/uwC9k/6/
首先,我试图在模板工作后如何初始化控件(其中,我认为此时我做的很多)
link: function(scope, element, attr) {
attr.$observe('dpid', function(value) {
if(value) {
$('#' + scope.dpid).datetimepicker({
language: 'en',
pick12HourFormat: true
});
}
Run Code Online (Sandbox Code Playgroud)
当我把它放在link指令中时,它什么也没做.我甚至没有看到任何错误.scope.dpid确实显示了控件的ID,所以我认为它会起作用.但是唉,我对javascript的了解,告诉我,我不在范围之内,或者是一些无法访问元素的废话.
一旦我开始这样做,我不确定如何以表格形式访问这些数据.
任何帮助是极大的赞赏.
更新 基本位工作,现在我需要知道如何将新控件中的数据导入我的控制器.这是更新的新jsfiddle的链接. http://jsfiddle.net/tmZDY/1/
更新2 我想我对如何使这些数据可访问有了一个想法但是我对javascript缺乏了解又让我感到又干.
当我创建对象时,我就这样做了.
var elDatepicker = element.datetimepicker({
language : 'en',
pick12HourFormat : true,
});
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用这个对象时,似乎没有得到正确的对象,或者我只是缺少一些基本知识.无论哪种方式,这肯定让我感到愚蠢.
console.log(elDatepicker.getDate());
Run Code Online (Sandbox Code Playgroud)
这失败了,getDate确实是一个方法,至少它看起来像是在插件的代码中.
我想按小时平均汇总数据.每日很容易:
apply.daily(X2,mean)
Run Code Online (Sandbox Code Playgroud)
为什么每小时没有功能?我试过了
hr.means <- aggregate(X2, format(X2["timestamp"],"%Y-%m-%d %H"))
Run Code Online (Sandbox Code Playgroud)
并且修剪参数总是出错.是否有类似apply.daily的更简单的功能?如果我想聚合5分钟的平均值怎么办?数据是每分钟的值:
"timestamp", value
"2012-04-09 05:03:00",2
"2012-04-09 05:04:00",4
"2012-04-09 05:05:00",5
"2012-04-09 05:06:00",0
"2012-04-09 05:07:00",0
"2012-04-09 05:08:00",3
"2012-04-09 05:09:00",0
"2012-04-09 05:10:00",1
Run Code Online (Sandbox Code Playgroud)
我正在使用xts和动物园.
angular ×6
angularjs ×2
javascript ×2
apache-spark ×1
events ×1
html5 ×1
jquery ×1
pyspark ×1
python ×1
r ×1
subscribe ×1
time-series ×1
try-catch ×1
typescript ×1
xts ×1
zoo ×1