0

In my website I'm using a service that needs an url to load an image.

How can I create an URL from an image that only exists in the filesystem of the project?

EDIT

I need the url for $og_image_url of Socialshare service.

1
  • by using relative path? Commented Dec 14, 2016 at 10:15

2 Answers 2

1

An angular have separate directive called ng-src

<img ng-src="http://www.gravatar.com/avatar/{{hash}}" alt="Description" />

or

<img ng-src="img/image.png" alt="Description" />
Sign up to request clarification or add additional context in comments.

2 Comments

But i don't want to use it in html. I need the url in controller.
@kilkus You can declare the $scope variable for image url param. Ex $scope.serverUrl use to ng-src={{serverUrl}}
1

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.image="http://helpacoder.com/wp-content/uploads/2015/07/angular.jpeg";
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
  <h1>Angular</h1>
    <img ng-src="{{image}}">
  <h4>Or</h4>
  <div ng-init="images='http://helpacoder.com/wp-content/uploads/2015/07/angular.jpeg'">
  <p>Another Way </p>
    <img ng-src="{{images}}"/>
  </div>
</div>

Two way to display the image in angular js.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.