设置<a href=""> as a variable

时间:2015-12-22 14:05:29

标签: javascript html css angularjs web-applications

I'm working on a web app where I'm using an object array to declare values that I will print out using <p ng-repeat="var game in download.game">{{value}}, {{value}}</p>and so on.

I also wanted to use a download button for the user to download the files. But using a normal a element, I could only add one link to a specific file. So I was wondering how I could assign a variable to my link so that I could instead have {{download-link}}.

Any suggestions?

2 个答案:

答案 0 :(得分:1)

试试这个:

控制器:

$scope.data = [
  {
    link: "http://link.com",
    text: "link.com"
  },
  {
    link: "http://link1.com",
    text: "link1.com"
  },
  {
    link: "http://link2.com",
    text: "link2.com"
  }
];

查看:

<div ng-repeat="element in data">
  <a href="{{element.link}}">{{element.text}}</a>
</div>

Codepen: http://codepen.io/anon/pen/LGZrMm

答案 1 :(得分:0)

我不确定我的问题是否正确,但尝试类似:

<div ng-repeat="var game in download.game">
  <a ng-href="{{game.link}}">{{game.value1}}, {{game.value2}}</a>
</div>

成为game.link,其他变量是您要打印的变量。

您应该尝试避免将Angular变量打印到非角度属性中。因此,请尝试使用ng-hrefng-click等。