How to apply class to div dynamically using AngularJS - html

I want to switch to div with class="col-md-x" depending upon the number of student object i am receiving.
E.x: Sample
if i am getting only one JSON object then i want to a div with class should be like(class="col-md-12").
if am getting two JSON object then i want to switch to a div with class="col-md-6".
<div class="container">
<div class="row">
<div class="col-md-12">
<div clss="row">
<div ng-repeat="c in vm.students" class="col-md-12">
<div calss="thimbnail">
<div class="Option div 1">
</div>
</div>
</div>
<div ng-repeat="c in vm.students" class="col-md-6">
<div calss="thimbnail col-md-">
<div class="Option div 2">
</div>
</div>
</div>
<div ng-repeat="c in vm.students" class="col-md-4">
<div calss="thimbnail col-md-">
<div class="Option div 3">
</div>
</div>
</div>
</div>
</div>
</div>
</div>

Use ng-class like below,
ng-class="{class}[condition]"
In your case ,
ng-class="{1:'col-md-12', 2:'col-sm-6'}[vm.students.length]"
For your reference, Detailed explanation

You have calss instead of class in the example code. I hope that is a typo.
To address to your problem you can make use of ng-class where you can assign classes based on conditions
More document on ng-class
Code Snippet:
<div class="container">
<div class="row">
<div class="col-md-12">
<div clss="row">
<div ng-repeat="c in vm.students" ng-class="{col-md-12:vm.students.length === 1,col-md-6:vm.students.length === 2">
<div calss="thimbnail">
<div class="Option div 1">
</div>
</div>
</div>
</div>
</div>
</div>
</div>

Related

Last block of grid not working in grid-row. Want to move the block till the next row from row 4 to 5

SIMPLE CALCULATOR DESIGN WITG GRID (ALL CODE PASTED)
Trying hard but the last equal(=) is not working
<div class="calculator">
<div class="display-area"></div>
<div class="button-section">
<div class="rows">
<div class="first-row">
<div id="cancel">C</div>
<div id="divide">/</div>
<div id="multiply">*</div>
<div id="delete">Del</div>
</div>
<div class="second-row">
<div id="seven">7</div>
<div id="eight">8</div>
<div id="nine">9</div>
<div id="minus">-</div>
</div>
<div class="third-row">
<div id="four">4</div>
<div id="five">5</div>
<div id="six">6</div>
<div id="plus">+</div>
</div>
<div class="fourth-row">
<div id="one">1</div>
<div id="two">2</div>
<div id="three">3</div>
<div id="equal">=</div>
</div>
<div class="fifth-row">
<div id="percent">%</div>
<div id="zero">0</div>
<div id="dot">.</div>
</div>
</div>
</div>
</div>
</div>
This is the pic for css where the code not working properly. The last equal block is not working in grid-rows as i want it to move down till the last row
enter image description here
This is the result i got after many tries
enter image description here

Electron > Is this a bug?

I have this html structure :
<div class="wrapper2">
<div class="previewContainer2">
<div id="previewGroup">
<div id="filePreview">
<div id="icon">
<div id="whiteSheet"/>
<div id="extension">EXT</div>
</div>
</div>
<img id="thumbnail" src="assets/indesign.svg" />
<div id="fileName">aaa</div>
</div>
</div>
<div class="metadataContainer2">
</div>
</div>
But then once loaded in electron, the last div (.metadataContainer2) is moved inside the .previewContainer2 div :\
<div class="wrapper2">
<div class="previewContainer2">
<div id="previewGroup">
<div id="filePreview">
<div id="icon">
<div id="whiteSheet">
<div id="extension">EXT</div>
</div>
</div>
<img id="thumbnail" src="assets/indesign.svg">
<div id="fileName">aaa</div>
</div>
</div>
<div class="metadataContainer2">
<p>ncndnlkcd</p>
</div>
</div>
</div>
Did I do something wrong ?
If you follow the HTML5 rules a div tag can not be self closed. Check more on this site
So modify your original code line#6 to mentioned below.
<div id="whiteSheet"></div>

How to better display elements inside card?

i have a task where i should have information inside "card", it should be displayed like on my example(picture)
so here is my html
<div id="app">
<el-card shadow="always">
Dashboard
</el-card>
<el-card class="box-card">
<div slot="header">
<h2>Card name</h2>
<p>Challenge</p>
</div>
<div class="text item">
</div>
</el-card>
</div>
can you help me to place those "approved posts", "influences", "likes", "comments" like on picture?
let's say i don't have such big experience bud i think that i should use grid or table display...
can you show me some example or to show how could it be in my example?
Thank you!
i am using Vue.js and Element UI libruary
Basicaly you need to follow col's, if you're familiar with bootstrap. so 2 equal col does the job
ex:
<div class="row">
<div class="col-lg-12">
<div class="col-lg-6">
<label>Posts</label>
<label>545454</label>
</div>
<div class="col-lg-6">
<label>Influencer</label>
<label>56656</label>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="col-lg-6">
<label>Likes</label>
label>545454</label>
</div>
<div class="col-lg-6">
<label>Comments</label>
<label>56656</label>
</div>
</div>
</div>

AngularJS set parent height from ng-repeat

I have a ng-repeat that has a variable height.
If I use a fixed height everything looks good. But I need the height of the parent panel to adjust automatically according to the ng-repeat child elements, otherwise I have overflow problems.
Is there any way to do this?
With Fixed height (see overflow at the bottom):
Without Fixed Height:
The code of the panels:
<div class="my-panel" ng-repeat="x in month.days">
<div class="panel-today" ng-show="x.today">
TODAY
</div>
<div class="panel" ng-class="x.panel_class">
<div class="panel-heading {{x.weekend}}">{{x.day}} {{x.date | date : 'dd-MM'}}</div>
<div class="panel-body my-panel-body">
<div ng-show="x.suspension != ''" style="width: 100%; text-align: center">
<b>{{x.suspension}}</b>
</div>
<div ng-show="x.suspension == ''">
<div class="well well-sm day-well">
<div class="day_period">
<div class="pull-right">
{{x.times.day.from}}<br/>
{{x.times.day.to}}
</div>
<div class="day_head">DAY</div>
</div>
<div ng-repeat="grade in x.staff.day.m">
<div class="letterCircleM">
{{grade.code}}
</div> S SIPHO
</div>
<div ng-repeat="grade in x.staff.day.f" class="letterCircleF">
{{grade.code}}
</div>
</div>
<div class="well well-sm day-well">
<div class="day_period">
<div class="pull-right">
{{x.times.night.from}}<br/>
{{x.times.night.to}}
</div>
<div class="day_head">NIGHT</div>
</div>
<div ng-repeat="grade in x.staff.night.m">
<div class="letterCircleM">
{{grade.code}}
</div> S SIPHO
</div>
<div ng-repeat="grade in x.staff.night.f" class="letterCircleF">
{{grade.code}}
</div>
</div>
</div>
</div>
<div class="panel-footer">
<div class="panel-suspend" ng-show="x.suspension != ''">
SUSPENDED
</div>
<div ng-show="x.suspension == ''">
{{x.contract}}
</div>
</div>
</div>
</div>
If fixed height works for you, why don't you add it to the parent based on the length of the data you are repeating in ng-repeat via ng-style?
ng-style="{
'height': 30 * RepeatData.length + 'px'
}
30 is the height of one "repeated" block

Is there any bootstrap property like CSS clear?

I have this html
<div class="row">
<div class="col-md-6" id="temp-box" >
<img id="weather-icon" src='Icons/sunny.png'></img>
<span id="temperature">50F</span>
</div>
<div class="col-md-6" > <div class="text-center" id="coodrs-title" ><span>Current Location</span></div>
<div class="position">
You Current Latitude Is: <span id="lati"></span><br/>
You Current Longitude Is: <span id="lngi"></span>
</div>
</div>
</div>
and i want the img with id #weather-icon be placed above the element with id #temperature, but both of them be inside the same row. How can i do this?
Ankit Agarwal gave me the best solution. Boootstrap's clear class!!!
Better solution is to use .clear bootstrap class. It willl work perfectly
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-md-6" id="temp-box" >
<img id="weather-icon" src='Icons/sunny.png'></img>
<div class="clear"></div>
<span id="temperature">50F</span>
</div>
<div class="col-md-6" > <div class="text-center" id="coodrs-title" ><span>Current Location</span></div>
<div class="position">
You Current Latitude Is: <span id="lati"></span><br/>
You Current Longitude Is: <span id="lngi"></span>
</div>
</div>
</div>
You could nest rows, like so:
<div class="row">
<div class="col-md-6" id="temp-box">
<div class="row">
<img id="weather-icon" src=''>IMAGE</img>
</div>
<div class="row"><span id="temperature">50F</span>
</div>
</div>
</div>
I'm not sure if this is the best way to to this, but it works.
Try setting:
#weather-icon {
display: block;
}
Currently you have an img & a span next to each other, which are both creating inline boxes. One way to force your image to have a line of its own is to set it to a block box element. At least that's my understanding of how it works.
Codepen:
http://codepen.io/anon/pen/pjzBRv
View code:
<div class="row">
<div class="col-md-6" id="temp-box" >
<img id="weather-icon" src='Icons/sunny.png'></img><br>
<span id="temperature">50F</span>
</div>
<div class="col-md-6" >
<div class="text-center" id="coodrs-title" ><span>Current Location</span></div> <div class="position"> You Current Latitude Is: <span id="lati"></span><br/> You Current Longitude Is: <span id="lngi">
</span>
</div>
</div>
</div>
In the code next "img" there is "br".