Can't append AngularJS array - html

I hope the title isn't too confusing.
I have an array in my angular.js file:
var app = angular.module('resume', []);
app.controller('resumeCtrl', function($scope, $document) {
$scope.projects = [
{
title: 'TRU Colors Brewing Co.',
image: 'images/tcb_screenshot.png',
url: 'https://www.trucolors.co',
category: ['development', 'design']
},
{
title: 'JOMO',
image: 'images/jomo_screenshot.png',
url: 'https://jeffberlin.github.io/JOMO_website/index.html',
category: 'development'
}
];
And in my HTML file I have:
<div class="row portfolio-preview">
<div class="col-lg-4 text-center" ng-repeat="x in projects">
<div class="projects tab-content active">
<figure class="tab-pane">
<a ng-href="{{x.url}}" target="_blank">
<img class="img-fluid screenshot" ng-src="{{x.image}}">
</a>
</figure>
<div class="description">
<a href="" target="_blank">
<h5>{{x.title}}</h5>
</a>
</div>
</div>
</div>
Now my issue is, I get the correct number of boxes to show with the titles, but nothing else displays/shows from the array. For reference, this section will have 3 options in the nav area and filter them out (by the category), assuming that's the best to do it. Can anyone see something I might be doing wrong?
The HTML code shown is the only way I've been able to at least get the titles to show up by using x in projects and the x.image, x.title, etc.
P.S.- I'm very new to Angular, but appreciate you all taking the time to help!

You need to provide a relative path to your images folder. The path needs to be relative to where your html file is so the browser knows where to look properly.
Add ./ in front of your image url.
$scope.projects = [
{
title: 'TRU Colors Brewing Co.',
image: './images/tcb_screenshot.png',
url: 'https://www.trucolors.co',
category: ['development', 'design']
},
{
title: 'JOMO',
image: './images/jomo_screenshot.png',
url: 'https://jeffberlin.github.io/JOMO_website/index.html',
category: 'development'
}
];
and as pointed out in the comments your css might be causing the image to be hidden or not have a width or height. So when debugging don't forget to check the css.

Related

How can I generate dynamic url in a list?

I get a list from my backend:
[
{
'name': 'nameA',
'codename': 'codenameA'
},
{
'name': 'nameB',
'codename': 'codenameB'
},
{
'name': 'nameC',
'codename': 'codenameC'
}
My goal is to display a list of owner.name with a url like http://myurl/owner/edit/${{ owner.codename }} using VueJS.
Currently my code is :
<template>
<div class="container my-3">
<div class="row">
<div class="col-8">
<ul v-for="owner in this.databaseOwners" :key="owner.name" class="list-group">
<li class="list-group-item">
{{ owner.name }}
</li>
</ul>
</div>
</div>
</div>
</template>
But it doesn't work, how can I use dynamic URL in my case? I'm really new to frontend so I'm sorry if my question seems really trivial.
Try this:
Make a new method under methods property of your Vue component:
methods: {
url(codename) {
return `/admin/owner/${codename}`;
}
}
And use it like this:
<a :href="url(owner.codename)">...</a>
Pay attention to the colon symbol:
:href
It means that it will try and bind the href attribute to some variable/method/computed property that is coming from the Vue component
This works : <a :href="'/admin/owner/' + owner.codename">{{ owner.name }}</a>
this may work
<a :href="'localhost:8080/admin/owner/'+owner.codename " target="_blank" rel="noreferrer noopener">{{ owner.name }}</a>

Vue.JS and figures/captions

I'm working on my new website design and decided to incorporate Vue.JS which I know very little about but am learning as I redesign my website.
I am using a Vue app to load different pages on my site.
I am also using it to load the image gallery, so I have all my images placed into an array in the app and they load just fine into the HTML.
I decided to use figures and want to place a caption beneath each image.
What I'm trying to do is place the figcaption text in the vue app, as part of the image array and have it load each text that belongs with each image.
this is the code i have for the html:
<div id="images" class="gallery content" v-if="gallery" v-for='img in imgs'>
<figure>
<img class="gallery-img" id="img.id" :src="img.url" :alt="img.alt" v-on:click="showModal">
<figcaption> a caption </figcaption>
</figure>
</div>
the "a caption" is just a place taker right now so i can see what it looks like on the site but i want that replaced with the actual caption which would be set in the vue app which is below.
js:
<script>
const test = Vue.createApp({
data(){
return{
home: true,
gallery: false,
store: false,
about: false,
imgs: [
{ url: 'images\\wood_gallery\\pens\\pen0.jpeg', id: 'pen0', alt: 'an image', caption: 'Pen kit: Skeleton key \n Wood: unknown' },
.... rest of the vue app code which is fine and works so not necessary to show.
Question: Can I do it this way and how do I access that 'caption' portion of text and put it into the html as text?
Simply use img.caption in the figure tag to display the caption content.
<figure>
<img class="gallery-img" id="img.id" :src="img.url" :alt="img.alt" v-on:click="showModal">
<figcaption>{{ img.caption }}</figcaption>
</figure>
I think this works fine.
<div id="images" class="gallery content" v-if="gallery" v-for='img in imgs'>
<figure>
<img class="gallery-img" id="img.id" :src="img.url" :alt="img.alt" v-on:click="showModal">
<figcaption v-html=“caption”></figcaption>
</figure>
</div>
const test = Vue.createApp({
data(){
return{
home: true,
gallery: false,
store: false,
about: false,
caption:"<h1>hi</h1>",
imgs: [
{ url: 'images\\wood_gallery\\pens\\pen0.jpeg', id: 'pen0', alt: 'an image', caption: 'Pen kit: Skeleton key \n Wood: unknown' },

Getting Images in the form of Grid in AngularJS

How to display all the images in the form of grid, which all will come from back end, so the images are in the dynamic form. and I have to put Description as well on those images, and those Description are also coming from Back End in AngularJS?
If image data is coming in array then you can show image using ng-repeat directive.
Controller
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.imageList = allImage;
});
HTML
<div class="col-md-3" ng-repeat="image in imageList track by $index">
<img src="{{image.imageUrl}}" />
<label> {{image.description}} </label>
</div>
You can use ng-repeat for showing you image with description like:
<li class="col-sm-3" ng-repeat="product in productList">
<img src={{product.imageUrl}} />
<label>{{product.description}}</label>
</li>
Here is the documentation

How to pass info to directive when looping through Angular array?

I am using an array of objects to populate info in a directive, but I do not know, when looping through that array, how to insert each object in the array into the "info" parameter of my directive.
Basically, the HTML template uses data passed to it in the info parameter, like so:
<directive info="{{angular object}}"></directive>
I know how to do this when I've hard-coded individual objects in the controller, like so:
$scope.object1 = {...values here...}
$scope.object2 = {...values here...}
etc.
For this I use:
<directive info="object1"></directive>
<directive info="object2"></directive>
But when I'm looping, I can't do that because I need to repeat the directive for each object in the array.
Here's what i've got
<div class="main" ng-controller="MainController">
<div class="container">
<div class="card" ng-repeat="app in apps">
<app-info info="{{app}}"></app-info> <!--HERE IS MY PROBLEM-->
</div>
</div>
</div>
Obviously I have no idea how or what to put as a value for the "info" parameter.
My MainController is as follows:
$scope.apps = [
{
icon: 'img/move.jpg',
title: 'MOVE',
developer: 'MOVE, Inc.',
price: 0.99
},
{
icon: 'img/gameboard.jpg',
title: 'Gameboard',
developer: 'Armando P.',
price: 1.99
},
{
icon: 'img/forecast.jpg',
title: 'Forecast',
developer: 'Forecast',
price: 1.99
},
{
icon: 'img/shutterbugg.jpg',
title: 'Shutterbugg',
developer: 'Chico Dusty',
price: 2.99
}];
The result is empty, meaning when I load the webpage, there is nothing there.
Just remove brackets. You were close.
<div class="main" ng-controller="MainController">
<div class="container">
<div class="card" ng-repeat="app in apps">
<app-info info="app"></app-info> <!--HERE IS NO PROBLEM-->
</div>
</div>
</div>

Load view after data is loaded

I have some trouble. I am using this plugin "angular-masonry" (it's on Github) to dynamically build the grid on the page. When the page loads I get this:
http://joxi.ru/YBQPVP3JTJCwfIgLgbc
Here is my code:
<div class="container" style="width:80%">
<h1 style="text-align: center; margin-bottom: 40px">
Category: {{category.text}}
</h1>
<div>(masonry='' load-images="false")
<div class="masonry-brick" ng-repeat="portal in category.claim_portals" style='width:50%;float:left'>
<div>
<h3>(style='margin-left:30px')
Portal: {{portal.text}}
</h3>
<div class="category-list" ng-repeat="claim in portal.portal_claim" style="margin-bottom:2px">
<div class="claim_sections">
<claimforlist claim="claim"></claimforlist>
</div>
</div>
</div>
</div>
</div>
</div>
But after resizing browser window, everything becomes normal and looks like this:
http://joxi.ru/iBQPVP3JTJCUfLnoqQQ
I think that view loads earlier than JSON data arrives.
Can anyone help and tell me how can I load view after the data has arrived? Or if you know another reason of such an issue, please reply.
Thanks in advance.
You can add a scope boolean variable with value set to false, and change the value to true on your http promise success.
Code sample:
function myController($scope, YourDataServer) {
$scope.dataLoadedSuccessfully = false;
yourDataServer
.query()
.$promise
.then(
function(result) {
$scope.dataLoaded = true; // set the value to true
});
}
HTML would look like:
<div id="loadingBar" ng-show="!dataLoadedSuccessfully">Loading data...</div>
<div id="dataWrapper" ng-show="dataLoadedSuccessfully">
<!-- data goes here -->
</div>