1

我的代码:

<li class="grid--col2of10" ng-repeat="button in buttons">
   <button ng-show="button.show" class="btn--action-{{button.color}} icon-{{button.icon}}" ng-click="{button.clickAction}">{{button.text}}</button>
</li>

我的对象:

var btns = {
    "back": {
      "color": "red",
      "clickAction": "prevStep",
      "icon": "left",
      "text": "Back"
    }, 
    "cancel": {
      "color": "red",
      "icon": "block",
      "text": "Cancel"
    },
    "clear": {
      "color": "blue",
      "icon": "cancel",
      "text": "Clear"
    },
    "save": {
      "color": "green",
      "icon": "download",
      "text": "Save"
    },
    "next": {
      "color": "green",
      "clickAction": "nextStep",
      "icon": "right-after",
      "text": "Save and Continue"
    }
  };

是否可以创建button.clickAction一个在 AngularJS 中执行的函数?

btns 对象在指令内,使用指令templateUrl选项调用 html。

4

1 回答 1

0

弄清楚了。我无法在 HTML 中执行它,但我通过调用指令对象中的函数使其工作:

var btns = {
    "back": {
      "color": "red",
      "clickAction": function() { prevStep(); },
      "icon": "left",
      "text": "Back"
    }, 
    "cancel": {
      "color": "red",
      "icon": "block",
      "text": "Cancel"
    },
    "clear": {
      "color": "blue",
      "icon": "cancel",
      "text": "Clear"
    },
    "save": {
      "color": "green",
      "icon": "download",
      "text": "Save"
    },
    "next": {
      "color": "green",
      "clickAction": function() { nextStep(); },
      "icon": "right-after",
      "text": "Save and Continue"
    }
  };

和 HTML:

<li class="grid--col2of10" ng-repeat="button in buttons">
   <button ng-show="button.show" class="btn--action-{{button.color}} icon-{{button.icon}}" ng-click="button.clickAction()">{{button.text}}</button>
</li>
于 2013-04-08T15:05:41.373 回答