0

I'm trying to add country image along with language using Angular JS.

<div ng-app class="nav">
<div></div>
<div ng-controller="MainController">
    {{selectedValue}}
    <ul>
        <li ng-repeat="lang in languages"><a ng-class="{selected: lang==selectedValue}" ng-click="changeSelectedValue(lang)" href="#">{{lang}}</a></li>
    </ul>  

</div>
</div>

<script>
function MainController($scope) {
$scope.languages = ['<img></img>English','Espanol', 'Française', 'Italian'];
    $scope.selectedValue = 'English';

    $scope.changeSelectedValue = function(lang) {
        $scope.selectedValue = lang;
    }
}
</script>

Here is the fiddle http://jsfiddle.net/RdNw4/6/

Am I missing any code here?

1 Answer 1

1

Take the image tag out of the languages array and rework your model so that the languages look something like:

$scope.languages = [ { name: 'English', image: '/images/english.png' },
    { name: 'Espanol', image: '/images/espanol.png' }
    etc.
];

Then change your markup to add an image tag:

<ul>
    <li ng-repeat="lang in languages">
        <img ng-src='{{lang.image}}' /> //for correct url
        <a ng-class="{selected: lang==selectedValue}" href="#">{{lang.name}}</a>
    </li>
</ul>  
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.