-1

我有这个数组stateData.submenu

[
  {
    "template": "<span>myContacts</span>",
    "sref": "contact.list"
  },
  {
    "template": "<span>myProjects</span>",
    "sref": "project.list"
  },
  {
    "template": "<span>myRecommendations</span>
      <span class=\"badge\">{{ notificationBadge }}</span>",
    "sref": "recommendation.list"
  }
]

对于数组的第三个元素中$interpolatetemplate属性,我做(解释{{ notificationBadge }}表达式):

this.interpolateTemplate = this.$interpolate(stateData.submenu[2].template)(this)

但它不是很干净,我想创建一个循环来迭代template数组的所有属性和$interpolate.

我该怎么做 ?

4

1 回答 1

1

正如你所说,你可以迭代你的模板,然后 $interpolate,就像这样。

var self = this;
this.notificationBadge = "Just a test"
this.templates = [{
     "template": "<span>myContacts</span>",
     "sref": "contact.list"
   },{
     "template": "<span>myProjects</span>",
     "sref": "project.list"
   },{
     "template": "<span>myRecommendations</span> < span class=\"badge\">{{ notificationBadge }}</span>",
     "sref": "recommendation.list"
   }].map(function each(template){
        template.template = $interpolate(template.template)(self)
        return template;
    })
于 2017-11-08T11:55:38.150 回答