簡體   English   中英

是否可以在自定義指令中使用理解表達式?

[英]Is it possible to use comprehension expressions in custom directives?

有沒有一種方法可以使用類似於ng-options使用的理解表達式來創建一組單選按鈕或復選框?

app.js

angular
    .module("app", [])
    .controller("controller", ["$scope", function($scope){
        $scope.selectedRadio = null;
        $scope.selectedCheckboxes = [];
        $scope.radioOptions = [
                    //some options...
             ];
        $scope.checkboxOptions = [
                    //some options...
             ];
    }]);

的index.html

<div data-ng-app="app" data-ng-controller="controller>
    <radio-group ng-radios="option as option.option_label
                            for option in radioOptions
                            track by option.option_id"
                 ng-model="selectedRadio"
                 ng-selected="option.selected" />
    <checkbox-group ng-checkboxes="option as option.option_label
                                   for option in checkboxOptions
                                   track by option.option_id"
                    ng-model="selectedCheckboxes"
                    ng-selected="option.selected"  />
</div>

我希望避免使用復雜的正則表達式來支持所有形式的理解表達式。

因為ngOptions (以及ngRepeat )提供自定義表達式語法是因為它被編碼為支持它

為了支持第三方指令中的自定義表達式,應使用regexps手動解析屬性值-從現有指令中借用或從頭開始編寫。

除了$interpolate$parse服務支持的基本Angular表達式之外, Angular中沒有內置的表達式魔術。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM