请问关于AngularJS里数组对象的使用例子问题

 self.getNoteClass = function(status) {
    return {
        done: status,
        pending: !status
    };
  };  

我在书中遇到这样一个用法,传入参数必须是true或false,然后传入true就是返回done,false就是返回pending。
我想问下这种用法是angularjs里的特殊用法吗?表示不理解,请大神解答,谢谢!
PS:下面这个我自己写的例子是我比较能理解的一个较简单清楚的使用方式。

self.getClassname = function(string) {
    var obj = {
      '1' : even,
      '2' : odd
    };
    return obj[string];
  };
阅读 15.9k
1 个回答

I guess this is meant to be used in conjunction with the ng-class built-in directive, in which case, the className done will be applied to the element when status is true, and className pending will be applied to the element otherwise.

You may see the "Map Syntax Example" section in the document for ng-class for reference.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进