0

ng-if を使用して、次のような条件を実行できることはわかっています。

  td.icon(ng-if="isAuthor()", colspan="2")
  td.icon(ng-if="!isAuthor()", colspan="3")

しかし、単純なものにしては少し冗長に思えます。方法はありますか:

  td.icon(ng-if="!isAuthor()", colspan="{{if isAuthor(): 2 else 3}}")
4

1 に答える 1

0

それを行う機能を持つことができます!

td.icon(colspan="getColspan()")

そしてあなたのコントローラーで:

$scope.getColspan = function () {
    if (isAuthor()) {
        return 2;
    } else {
        return 3;
    }
};
于 2013-06-26T04:29:15.203 に答える