gpt4 book ai didi

javascript - 语法错误: Unexpected token { in directive angular js

转载 作者:行者123 更新时间:2023-12-03 09:30:17 25 4
gpt4 key购买 nike

我在访问 html 文件 {{model}} 中的作用域变量时遇到错误

在我的 html 文件中

<div shipping-Detail-Directive type="billingAddress"> </div>

这是我的要求 我希望用户在“type”属性中填写值,并且我必须在 ShippingDetailDirective.html 文件中访问它

我知道我在访问指令模型时做错了。

在我的 ShippingDetailDirective.html 中

<div class="order-content shipping-cost-confirm" ng-repeat="x in order">


<div><span>Name</span><label>:</label><span>{{x.{{model}}.firstName}} {{x.{{model}}.lastName}}</span></div>
<div><span>Company</span><label>:</label><span>{{x.{{model}}.companyName}}</span></div>
<div><span>Address</span><label>:</label><span>{{x.{{model}}.address}}</span></div>
<div><span>City</span><label>:</label><span>{{x.{{model}}.city}}</span></div>
<div><span>State / Province</span><label>:</label><span>{{x.{{model}}.state}}</span></div>
<div><span>Zip Code</span><label>:</label><span>{{x.{{model}}.zipCode}}</span></div>
<div><span>Country</span><label>:</label><span>{{x.{{model}}.country}}</span></div>
<div><span>Office Tel</span><label>:</label><span>{{x.{{model}}.officeTelephone}}</span></div>
<div><span>Home Tel</span><label>:</label><span>{{x.{{model}}.homeTelephone}}</span></div>
<div><span>Fax</span><label>:</label><span>{{x.{{model}}.fax}}</span></div>
<div><span>Mobile Phone</span><label>:</label><span>{{x.{{model}}.mobileNo}}</span></div>
<div><span>E-mail Address</span><label>:</label><span>{{x.{{model}}.email}}</span></div>
<div class="edit-forgot float-r o-view-btn">
<input type="button" ui-sref="app.Billing" value="EDIT ADDRESS" class="white-bg"></div>
</div>

这是我的指令

app.directive('shippingDetailDirective', function() {
return{
scope: {
model: '='
},
templateUrl: 'templates/ShippingDetailDirective.html',
controller: 'ShippingCtrl',
link : function (scope, elem, attrs, controller) {
scope.model = attrs.type;

}
}

});

所以有人可以告诉我还有其他方法可以做到这一点吗?

最佳答案

我猜您想将 {{x.{{model}}.firstName}} 替换为 {{x[model].firstName}},但我们必须查看您的数据才能知道。

关于javascript - 语法错误: Unexpected token { in directive angular js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31531971/

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