angular.js - How to give default values ​​to variables in html pages in angularjs?
淡淡烟草味
淡淡烟草味 2017-05-15 16:54:28
0
1
589

Requirement description: There is a myimg variable in the page. I can use $scope.myimg='xxx' in the controller to give it an initial value. But if assignment is not allowed in the control, what about in the img tag? Give it an initial value?

I tried ng-init="myimg:XXX", but in this case the image cannot be displayed
<img ng-src='./img/{{myimg}}.png'>
淡淡烟草味
淡淡烟草味

reply all(1)
淡淡烟草味

This is the same operation as adding a default value when initializing a value in JavaScript, just use ||.

<img ng-src='./img/{{myimg || 'default'}}.png'>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template