gpt4 book ai didi

javascript - 是否可以链接指令范围(例如 obj.prop)?

转载 作者:行者123 更新时间:2023-11-29 10:10:35 25 4
gpt4 key购买 nike

我有以下指令:

  template: '<form novalidate class="form-inline" ng-submit="submit($event, building)">' +
'<div class="form-group">' +
'<label class="form-control-static">{{label}}</label>' +
'</div>' +
'<div class="form-group">' +
'<input name="input" class="form-control" type="text" ng-model="model" />' +
'</div>' +
'<input class="btn btn-default" type="submit" value="Submit" />' +
'</form>',
scope: {
label: "@",
building: "=",
model: "=",
//type: "=",
},

现在我必须在 HTML 中写这样的东西:

<building-field label="name" building="building" model="building.name"></building-field>

我想通过添加 buildinglabel 来简化它(然后将它们放在指令 ng-model="中建筑物名称):

<building-field label="name" building="building"></building-field>

问题是,我不知道如何传递两个指令范围并将它们作为 obj.prop。如何做到这一点?

最佳答案

你不需要做任何特别的事情,支持 obj.prop。在您的模板中:

<input name="input" class="form-control" type="text" ng-model="building[label]" />

作为旁注,您正在使用插值(类型 @)绑定(bind) label。这意味着您将始终在 scope.label 中拥有字符串 "name"。如果你想真正传递name的值,你需要使用双大括号:

<building-field label="{{name}}" building="building"></building-field>

关于javascript - 是否可以链接指令范围(例如 obj.prop)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34302939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com