1

We've decided to use Mean.io in order to get a quick MEAN stack installation, but we're finding some troubles to get things done.

I'm trying to show a picture from my header js controller. But it doesn't show up. In fact, what i see when i open the inspector is just:

<img ng-src>

This is my HTML code, located in header.html:

<div class="page-header" data-ng-controller="HeaderController">
   <div class="logo pull-left">
       <a class="navbar-brand" ui-sref="home"><img ng-src="{{image.logo}}"/></a>
   </div>
</div>

As you may see, i've put "ng-src" and the var taken from the js controller.

This is the HeaderController:

'use strict';

angular.module('mean.system').controller('HeaderController', ['$scope', '$rootScope', 'Global', 'Menus',
  function($scope, $rootScope, Global, Menus) {
    $scope.global = Global;
    $scope.menus = {};
    $scope.image = {
      logo: 'assets/img/logo.png'
    };

    // Default hard coded menu items for main menu
    var defaultMainMenu = [];

    // Query menus added by modules. Only returns menus that user is allowed to see.
    function queryMenu(name, defaultMenu) {

      Menus.query({
        name: name,
        defaultMenu: defaultMenu
      }, function(menu) {
        $scope.menus[name] = menu;
      });
    }

    // Query server for menus and check permissions
    queryMenu('main', defaultMainMenu);

    $scope.isCollapsed = false;

    $rootScope.$on('loggedin', function() {

      queryMenu('main', defaultMainMenu);

      $scope.global = {
        authenticated: !! $rootScope.user,
        user: $rootScope.user
      };
    });

  }
]);

The template var is working correctly because if i put {{image.logo}} elsewhere it prints "assets/img/logo.png".

Suggestions? What am i missing?

Thanks in advance!

3
  • 1
    While the variable may be working, is the image at that location? Try prepending the logo route with a /. Commented Aug 12, 2014 at 15:36
  • Now, although i've changed the route the image doesn't still appear. Now, the img displays this way in the inspector: <img ng-src="/system/assets/img/logo.png" src="/system/assets/img/logo.png"> Commented Aug 12, 2014 at 15:57
  • the tag displays correctly and thus it's probably the location of your image that's off. Commented Aug 12, 2014 at 18:00

1 Answer 1

2

I had the similar problem, I did the same as you have done and was getting 404 error for the PNG. When reviewed the other requests that are made, I came up with, you must pass the "package name" in the parameter logo as well.

Just as;

$scope.image = {
      logo: 'system/assets/img/logo.png'
    };

Than the logo is displayed as desired

Sign up to request clarification or add additional context in comments.

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.