In my main html file I have the following.
<div class="row">
<div class="col-md-6">
<!--Here go the partials -->
<div ng-view></div>
</div>
<div class="col-md-6">
<div id="imageHolder">
<img src="{{selectedItem}}">
</div>
</div>
</div>
ng-view displays a form and for imageHolder I wanted to display a dynamic image based on a select option from the form.
So the form in ng-view has the following input
<div class="form-group" ng-class="{ 'has-error': emailform.inputLinks.$invalid && emailform.inputLinks.$dirty }">
<label for="inputLinks" class="col-lg-4 control-label">Link to be sent</label>
<div class="col-lg-8">
<select class="form-control" ng-model="formData.inputLinks" data-ng-options="link.value as link.label for link in links" id="inputLinks" required>
<option value="">Please select</option>
</select>
</div>
</div>
And then in my controller, I have
$scope.links =
[
{ label: 'label1', value: '/app/img/placeholder.jpg'},
{ label: 'label2', value:'/app/img/placeholder.jpg'}
];
Now if I look at the select, I can see my options label1 and label2. If one of these is select, I wanted to set the image src in my main html file to the value of its scope.
How could I achieve this?
Thanks
UPDATE I can't seem to get it to work because my set up is different to examples I see. For instance, I dont have an ng-controller. Instead, I have
<div class="container" ng-app="emailGeneratorApp">
<div class="row">
<div class="col-md-6">
<!--Here go the partials -->
<div ng-view></div>
</div>
<div class="col-md-6">
<div id="imageHolder">
<img ng-src="{{formData.inputLinks}}">
</div>
</div>
</div>
</div>
And then I have a file app.js which is like
'use strict';
// Declare app level module which depends on filters, and services
angular.module('emailGeneratorApp', ['emailGeneratorApp.filters', 'emailGeneratorApp.services', 'emailGeneratorApp.directives']).
config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/home', {templateUrl: 'partials/home.html', controller: EmailViewCtrl});
$routeProvider.otherwise({redirectTo: '/home'});
}]);
And finally controller.js is like
'use strict';
/* Controllers */
function EmailViewCtrl($scope, $http) {
$scope.links =
[
{ label: 'Email1', value: '/app/img/placeholder.jpg'},
{ label: 'Email2', value:'/app/img/placeholder.jpg'}
];
}
EmailViewCtrl.$inject = ['$scope', '$http'];
How can I get it to work with this kind of set up?
Thanks