Angular:如何将图片插入<a ui-sref=""> that uses ng-bind?

时间:2016-02-07 06:58:02

标签: angularjs

I have the following in my Angular view:

    <a ui-sref="mystate({'stateParam1': 99, 'stateParam1': 98})" ng-bind="myCtrl.something.something.username">
    </a>

    <img ng-src="http://www.gravatar.com/avatar/{{myCtrl.something.something.md5Email}}"/>

It works just fine. I can see a link (for my username). And it is followed by a nice Gravatar image of myself.

But I actually want my image and my username to both be in the body of the link.

I tried the following but it only showed my username, not the image:

    <a ui-sref="mystate({'stateParam1': 99, 'stateParam1': 98})" ng-bind="myCtrl.something.something.username"> 
      <img ng-src="http://www.gravatar.com/avatar/{{myCtrl.something.something.md5Email}}"/>
    </a>

So how can I make this work? It seems using ng-bind in the <a></a> tag overrides any text that is inserted between the opening and closing tags.

1 个答案:

答案 0 :(得分:1)

我认为你可以在没有ng-bind

的情况下做到这一点
<a ui-sref="mystate({'stateParam1': 99, 'stateParam1': 98})"> 
  {{ myCtrl.something.something.username }}
  <img ng-src="http://www.gravatar.com/avatar/{{myCtrl.something.something.md5Email}}"/>
</a>