gpt4 book ai didi

javascript - 如果我只有两个 if 条件,我该如何制定指令? - Angular Js

转载 作者:太空宇宙 更新时间:2023-11-04 16:00:05 24 4
gpt4 key购买 nike

嗨,有什么方法可以为这个 html 创建指令吗?我必须检查语言类型是否为阿拉伯语,然后应用 float:right,否则如果语言类型为英语,则不应用任何内容。

<div ng-show="show_div">
<div class="aa-properties-content-head mg-bt-10 font-size-13" ng-if="$root.lg_type =='en'">
<div data-ng-repeat="variant in variants">
<div class="col-md-{{columns}} col-sm-12 col-xs-12">
<label for="text">{{variant.name}}:</label>
<input type="text" name="variant_value{{$index}}" class="form-control" ng-model="variant.variant_value" ng-blur="search_category()" placeholder="{{$root.translated_labels.dashboard.enter}} {{variant.name}}" ng-minlength="2" ng-maxlength="30" required>
</div>
</div>
<div class="col-md-{{columns}}">
<label for="item_price">{{$root.tl['product-variant'].price}}:</label>
<input class="form-control" name="price" ng-model="search_price" placeholder="{{$root.translated_labels.dashboard.item_price}}" ng-minlength="1" ng-maxlength="20" id="item_price" type="text" required>
</div>
<div class="col-md-{{columns}}" id="prod_type_dd">
<label for="product_type_id">{{$root.tl.product.product_type_id}}:</label>
<input type="text" ng-model="product_type_id" placeholder="{{$root.translated_labels.dashboard.select_type}}" uib-typeahead="producttype.id as producttype.name for producttype in producttype_data | filter:$viewValue | limitTo:4" typeahead-input-formatter="formatLabel($model)"
class="form-control">
</div>
</div>


<div class="aa-properties-content-head mg-bt-10 font-size-13" ng-if="$root.lg_type =='ar'">
<div data-ng-repeat="variant in variants">
<div class="col-md-{{columns}} col-sm-12 col-xs-12 float-right">
<label for="text">{{variant.name}}:</label>
<input type="text" name="variant_value{{$index}}" class="form-control" ng-model="variant.variant_value" ng-blur="search_category()" placeholder="{{$root.translated_labels.dashboard.enter}} {{variant.name}}" ng-minlength="2" ng-maxlength="30" required>
</div>
</div>
<div class="col-md-{{columns}} float-right">
<label for="item_price">{{$root.tl['product-variant'].price}}:</label>
<input class="form-control" name="price" ng-model="search_price" placeholder="{{$root.translated_labels.dashboard.item_price}}" ng-minlength="1" ng-maxlength="20" id="item_price" type="text" required>
</div>
<div class="col-md-{{columns}} float-right" id="prod_type_dd">
<label for="product_type_id">{{$root.tl.product.product_type_id}}:</label>
<input type="text" ng-model="product_type_id" placeholder="{{$root.translated_labels.dashboard.select_type}}" uib-typeahead="producttype.id as producttype.name for producttype in producttype_data | filter:$viewValue | limitTo:4" typeahead-input-formatter="formatLabel($model)"
class="form-control">
</div>
</div>
</div>

如何将 Controller 的数据传递给指令?我已经从 Controller 加载数据,但我不知道如何将其传递到指令中,然后再次将其传递到 Controller 中。

最佳答案

你的意思是这样做?

.directive('alignmentBlock', function() {
return {
restrict: 'A',
link: function(scope, elem, attr, ctrl) {
if(scope.arabic)
elem.css({'float': 'right'});
}
};
});

评估您是否更新 bool 范围变量,无论用户是否切换到阿拉伯语/非阿拉伯语。

然后在 HTML 中你可以像这样使用这个指令:

<div alignmentBlock>
<p>your text</p>
</div>

关于javascript - 如果我只有两个 if 条件,我该如何制定指令? - Angular Js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42339245/

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