有人可以解释一下$q.whenAngularJS的工作原理吗?我正在尝试分析$http工作方式,并发现了这个:
var promise = $q.when(config);
Run Code Online (Sandbox Code Playgroud)
这是来自Chrome控制台的配置对象:
Object {transformRequest: Array[1], transformResponse: Array[1], cache: Object, method: "GET", url: "/schedule/month_index.html"…}
cache: Object
headers: Object
method: "GET"
transformRequest: Array[1]
transformResponse: Array[1]
url: "/schedule/month_index.html"
__proto__: Object
Run Code Online (Sandbox Code Playgroud)
接下来发生什么?该对象如何被解决或拒绝?
我有一个项目列表,点击它们应该给用户带来详细信息(另一个视图).在我的路由器中,我有这样的路线:
'details/:id' : 'details',
Run Code Online (Sandbox Code Playgroud)
现在,在详细功能中我应该获取我的对象(获取将触发新的视图渲染).但是我应该怎么做才能将骨干附加项ID发送到model.url?我现在有两种方式:
在获取时动态创建URL:
this.realty_object.fetch({url: SITE_PATH + 'blah/blah/' + id});
Run Code Online (Sandbox Code Playgroud)
这样的事情:
this.realty_object
.set({id : id}, {silent: true})
.fetch();
Run Code Online (Sandbox Code Playgroud)
但我怀疑这是正确的解决方案.怎么样?model.urlRoot和model.url()之间有什么区别.
我想在Angular应用程序中使用ES6类并试图像这样使用它:
'use strict';
class EditorCtrl{
constructor(){
this.something = "ASd";
}
foo(){
}
}
angular.module('Editor').controller('EditorCtrl', EditorCtrl);
Run Code Online (Sandbox Code Playgroud)
但由于某种原因,这段代码给了我一个错误:Class constructors cannot be invoked without 'new'.为什么会发生这种情况以及如何解决这个问题?
Angular:1.4.7 Chrome:46.0.2490.71
我阅读官方文档和大量的线程,但仍然找不到我的情况的解决方案.我的情况非常基本.我有2个实体:评论和关键字.一条评论可以包含许多关键字,但每个关键字仅适用于一条评论.关键字在关键字表格中不是唯一的.所以我认为这是一对多的关系.表结构简单如下:
关键字
id int(11)
comment_id int(11)
text varchar(30)
Run Code Online (Sandbox Code Playgroud)
评论
id int(11)
text text
Run Code Online (Sandbox Code Playgroud)
这是我如何映射它们:
/**
* @Entity
* @Table(name="comments")
**/
class Comments
{
/** @Id @Column(type="integer") */
private $id;
/** @Column(type="text") */
private $text;
/**
* @OneToMany(targetEntity="keywords", mappedBy="comment_id")
*/
private $keywords;
public function getText(){return $this->text;}
public function getId(){return $this->id;}
public function getKeywords(){return $this->keywords;}
}
/**
* @Entity
* @Table(name="keywords")
*/
class Keywords
{
/** @Id @Column(type="integer") */
private $id;
private $text;
public function getText(){return $this->text;}
public …Run Code Online (Sandbox Code Playgroud) 在我的所有测试之前(在量角器下运行jasmine)我必须登录到我的系统,如果登录失败,我不应该运行任何测试.但即使我使用proccess.exit(这是节点功能来暂停程序执行),测试仍然执行并且都失败了.
beforeAll(function(done){
mainPage.resize();
loginPage.login(env.regularUser).then(function(){
mainPage.navigate();
mainPage.waitLoading();
done();
}, function(){
process.exit(1);
});
});
Run Code Online (Sandbox Code Playgroud)
如何防止beforeAll块中的测试执行?
如何在Doctrine2中获取对数据库的查询次数?我只需要统计数据,并了解更多主义如何工作,在不同情况下产生多少查询.但无论如何,怎么做?
是否可以在多个对等连接中使用相同的SDP?
我正在使用WebRTC构建视频会议.我们的想法是,呼叫者使用一些信令机制,通过SDP(每个用户使用相同的SDP)向所有其他用户发送广播消息,然后用户将使用他们的SDP进行响应.
当用户收到某人的SDP时,他用它来设置远程描述,如下所示:
connection = new RTCPeerConnection()
desc = RTCSessionDescription({sdp: SDP, type: "offer"});
connection = setRemoteDescription(desc);
Run Code Online (Sandbox Code Playgroud)
这是SDP示例:
v=0
o=- 6843023960119608301 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE audio
a=msid-semantic: WMS
m=audio 1 RTP/SAVPF 111 103 104 0 8 106 105 13 126
c=IN IP4 0.0.0.0
a=rtcp:1 IN IP4 0.0.0.0
a=ice-ufrag:q36dZRVoaS4ixPYP
a=ice-pwd:K5yAm4A+zGoIKIgsX9o4VgDA
a=ice-options:google-ice
a=fingerprint:sha-256 62:3E:99:2F:FF:D4:58:7C:F0:A1:02:3F:09:2B:D1:F3:71:D7:F6:59:62:12:E4:1B:4A:68:01:4C:43:E0:D1:75
a=setup:actpass
a=mid:audio
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=recvonly
a=rtcp-mux
a=crypto:0 AES_CM_128_HMAC_SHA1_32 inline:Tdz5Z3KHB3Xosqr5D53WZfi7Zndz+932X3H46Qvf
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:NJO4XhhHUgiJRCfyYzDgajkCJAF/9BX8QeU+FKQs
a=rtpmap:111 opus/48000/2
a=fmtp:111 minptime=10
a=rtpmap:103 ISAC/16000
a=rtpmap:104 ISAC/32000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:106 …Run Code Online (Sandbox Code Playgroud) ECMAScript 6(Harmony)引入classes了从另一个继承的能力.假设我有一个游戏和一些基本类来描述机器人行为的基本内容.我简化了我的真实架构,但假设我需要运行render另一个例程,我将这些调用放在基本Bot类中.
class Bot{
constructor(){
render();
}
render(){}
}
Run Code Online (Sandbox Code Playgroud)
每个机器人然后覆盖它的render功能,并可以在构造函数中进行一些设置:
class DevilBot extends Bot{
constructor(){
super();
this.color = 0xB4D333;
}
render(){
createSomeMesh(this.color);
}
}
Run Code Online (Sandbox Code Playgroud)
这里的问题是在我打电话之前super()- this不存在.但是super(父构造函数)将调用render需要color在子构造函数中定义的变量的重写.我可以在父构造函数中假设子对象将实现一些init具有所有必需设置的函数并调用它:
class Bot{
constructor(){
if (this.init) this.init();
render();
}
render(){}
}
class DevilBot extends Bot{
init(){
this.color = 0xB4D333;
}
render(){
createSomeMesh(this.color);
}
}
Run Code Online (Sandbox Code Playgroud)
但这种方法有多好,什么是解决这种问题的首选方法?
我正在尝试编写简单的监视任务,它将监视我的测试文件并在更改时编译它们并使用gulp-jasmine运行.
我的手表任务:
gulp.task('watch', function () {
gulp.watch(['tests/**/[^_]*.ts'], gulp.series(['compile_tests', 'test']));
})
Run Code Online (Sandbox Code Playgroud)
和测试任务:
gulp.task('test', function(){
return gulp.src('tests/**/[^_]*.spec.js')
.pipe(
jasmine().on('error', function(error){
console.log(error);
this.emit('end');
})
);
});
Run Code Online (Sandbox Code Playgroud)
但是,如果经过测试的代码包含错误,例如is not a function或者其他什么,请监视任务崩溃,我必须一次又一次地重新启动它.我的错误处理程序甚至没有被调用.那么如何以正确的方式处理错误呢?
是否可以在类型签名中引用当前类类型?这样我就可以做这样的事情:
export class Component{
constructor(config?: { [field in keyof self]: any }) {
Object.assign(this, config)
}
}
Run Code Online (Sandbox Code Playgroud)
这个想法是传递一个包含当前类键的配置对象。
我可以使用接口,但随后我需要输入相同部分的代码(在接口和实现类中)
另一种方法是使用泛型。像这样的东西:
export class Component<T>{
init(config?: { [field in keyof T]?: any }) {
Object.assign(this, config)
}
}
class TestComponent extends Component<TestComponent>{
foo: number
}
const component = new TestComponent().init({ foo: 11 })
Run Code Online (Sandbox Code Playgroud)
但是拥有类似的代码class TestComponent extends Component<TestComponent>让我寻找更好的方法......
angularjs ×2
ecmascript-6 ×2
backbone.js ×1
deferred ×1
doctrine ×1
doctrine-orm ×1
gulp ×1
gulp-watch ×1
jasmine ×1
javascript ×1
php ×1
protractor ×1
q ×1
sdp ×1
typescript ×1
webrtc ×1