.my-div:before {
content: url('/pathToMyImage/image.png.png');
position: absolute;
}
我正在使用 Angular JS,图像应该是动态的。假设它的路径存储在 $scope.path
变量中。
例如:
$scope.path="/pathToMyImage/image.png";
如何传递$scope.path
的值来动态设置内容?
最佳答案
只需像这样在 Controller 中设置 $scope.path..
$scope.path="/pathToMyImage/image.png";
然后在您的 html 文件中访问它,如下所示。
{{path}}//用于数据绑定(bind)
假设 content.content_id
包含动态图像名称。然后路径将是
例如。 <img src="https://s3.amazonaws.com/gicontent/345X195/{{content.content_id}}.png" />
关于javascript - 使用 :before pseudo element to insert image having dynamic path in Angular JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23630269/