【发布时间】:2016-07-11 01:49:38
【问题描述】:
我想根据事件创建背景图像更改(特别是选择选项更改),但我无法在本地环境中获取图像路径。
我的图片路径在目录:http://localhost/webpage1/img/ 与图片yellow.jpg
我在我的应用程序 (<div ng-controller="myCtrl" ng-style="style") 中放置了一个 ng-style 指令并将其与控制器绑定:
app.controller('myCtrl', function($scope) {
$scope.options = [
{ type: 'yellow'},
{ type: 'green'}
];
//default image
$scope.subject = $scope.options[0].type;
$scope.image = $scope.subject + ".jpg";
$scope.style = {background: "url(" + $scope.image + ") no-repeat center center fixed"};
....
});
但是,我对检索图像的文件路径感到困惑。我不想列出整个文件路径,因为一旦我把它放上去,它就不一样了,所以像$scope.filepath = 'localhost/webpage1/img'; 这样的东西看起来非常混乱和丑陋。
编辑:我的选择选项
<select ng-model="subject" name="subject" class="subject" >
<option ng-repeat="type in options">{{ type.type }}</option>
</select>
【问题讨论】:
-
看看这个 SO 问题及其所有答案:stackoverflow.com/questions/13781685/…
标签: javascript css angularjs filepath