我正在写一个Angular 1.5指令,我遇到了一个令人讨厌的问题,试图在绑定数据存在之前对其进行操作.
这是我的代码:
app.component('formSelector', {
bindings: {
forms: '='
},
controller: function(FormSvc) {
var ctrl = this
this.favorites = []
FormSvc.GetFavorites()
.then(function(results) {
ctrl.favorites = results
for (var i = 0; i < ctrl.favorites.length; i++) {
for (var j = 0; j < ctrl.forms.length; j++) {
if (ctrl.favorites[i].id == ctrl.newForms[j].id) ctrl.forms[j].favorite = true
}
}
})
}
...
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我正在进行AJAX调用以获取收藏夹,然后根据我的绑定表单列表进行检查.
问题是,即使在填充绑定之前,承诺仍在实现......所以当我运行循环时,ctrl.forms仍未定义!
不使用$ scope.$ watch(这是1.5组件的吸引力的一部分)我如何等待绑定完成?
我希望能够将参数传递给ng-outlet引入的子组件.但我不知道该怎么做.
这是我的组件绑定的一个例子:
app.component('profile', {
bindings: {
section: '=',
currentUser: '<'
},
...
Run Code Online (Sandbox Code Playgroud)
通常我会像这样调用它:
<profile section="$ctrl.bio" current-user="$ctrl.selectedUser"></profile>
Run Code Online (Sandbox Code Playgroud)
但相反,我有这个:
<ng-outlet></ng-outlet>
Run Code Online (Sandbox Code Playgroud)
和一个传递配置文件的路由器.
$routeConfig: [
{ path: '/Profile/:id', name: 'Profile', component: 'profile' }]
Run Code Online (Sandbox Code Playgroud)
那么如何将火焰传递给这个组件的其他基本绑定,也许是无法编码到URL中的绑定?
谢谢,非常感谢帮助
编辑:我被要求提供一个更具体的例子,说明我想做什么.
我认为概念问题相当清楚,但这是一个特殊情况,其中传递路线参数显然是不够的.在我的App组件级别说我有一个事件回调函数onDeleteItem(id)
我该如何复制
bindings: {
onDeleteItem: "&"
}
...
<some-component on-delete-item="$ctrl.onDeleteItem(id)"></some-component>
Run Code Online (Sandbox Code Playgroud)
有一个出口?
使用 构建我的 Rust lambda 时cross,我收到此错误:
error: failed to run custom build command for `openssl-sys v0.9.58`
Run Code Online (Sandbox Code Playgroud)
当我查看我的依赖关系图时,openssl 甚至没有列出!这是怎么回事?
这是我的 Cargo.toml 文件:
[package]
name = "my_lambda"
version = "0.1.0"
authors = ["Thomas <>"]
edition = "2018"
autobins = false
[[bin]]
name = "bootstrap"
path = "src/main.rs"
[dependencies]
lambda_runtime = "0.2.1"
mysql = { version = "20.1.0" }
reqwest = { version = "0.9.24" }
serde = { version = "^1.0", features = ["derive"] }
Run Code Online (Sandbox Code Playgroud)
交叉文件
[target.x86_64-unknown-linux-gnu]
image = "lambci/lambda:build-provided"
[target.x86_64-unknown-linux-musl] …Run Code Online (Sandbox Code Playgroud) angularjs ×2
components ×2
aws-lambda ×1
javascript ×1
openssl ×1
reqwest ×1
router ×1
rust ×1
rust-cargo ×1