イベント(具体的には選択オプションの変更)で背景画像の変更を作成したいのですが、ローカル環境で画像パスを取得できません。AngularJS/JavasScriptのローカル画像パス
私のイメージパスがディレクトリである:イメージと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の質問とすべての答えを見てください:http://stackoverflow.com/questions/13781685/angularjs-ng-src-equivalent-for-background-imageurl – DotNetWala