Angularjs ngFileUpload adding new file overwrites last one - angularjs

So I am trying my luck with ng-file-upload. I have it set to upload multiple files, but each time I click the "upload file" button or "Drag and drop" the files (I have both options on the page), it seems to overwrite my previous files with the new ones I chose. Can someone help me fix up the code to allow for me to click the button twice to add to the same list?
Fiddle: http://jsfiddle.net/ptf5z9e5/2/
controller:
$scope.files = []
$scope.uploadFiles = function (files) {
$scope.files = files;
if (files && files.length) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
if (!file.$error) {
Upload.upload({
url: 'https://angular-file-upload-cors-srv.appspot.com/upload',
data: {
files: file
}
}).then(function (response) {
$timeout(function () {
$scope.result = response.data;
});
}, function (response) {
if (response.status > 0) {
$scope.errorMsg = response.status + ': ' + response.data;
}
}, function (evt) {
$scope.progress =
Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
});
}
}
}
};
HTML:
<div class="modal-content">
<div class="modal-header">
<span id="span" class="close" style="z-index: 99999;">×</span>
<!-- <div class="circle close" ></div> -->
<p id="uploadText">Upload Files</p>
<hr class="add-horizontal-line">
</div>
<div class="modal-body">
<ul>
<li ng-repeat="f in files" style="font:smaller" class="file-list"><p id="filesetup"></p>
<!-- file image -->
<div ng-if="vm.checkJPGFile(f.name) == 'jpg'">
<img src="app/assets/img/jepfimg.png" style="width: 28px; height: 33px; position: relative; left: 20px;" alt="" />
</div>
<div ng-if="vm.checkPNGFile(f.name) == 'png'">
<img src="app/assets/img/pngimg.png" style="width: 28px; height: 33px; position: relative; left: 20px;" alt="" />
</div>
<div ng-if="vm.checkPDFFile(f.name) == 'png'">
<img src="app/assets/img/pdfimg.png" style="width: 28px; height: 33px; position: relative; left: 20px;" alt="" />
</div>
<!-- filename -->
<div class="loadershow">{{f.name}} {{errFile.name}} {{errFile.$error}} {{errFile.$errorParam}}
<!-- loading message and progress bar -->
<br>
<span class="progress" ng-show="progress >= 0">
<div style="width:{{progress}}%" ng-bind="progress + '%'"></div>
</span>
<p style="margin-left: 2px;font-style: italics;font-family: 'Roboto', sans-serif; font-size: 12px;color: #818A8F;" ng-bind="'(' + progress + '%' + ' ' + 'complete)'"></p>
<!-- end of loading animation -->
<!-- <div class="input-field col s6 m6 l6">
<input placeholder="Note" id="first_name" type="text" class="validate active square-box">
<label for="first_name" class="active">Description</label>
</div> -->
</li>
<li ng-repeat="f in errFiles" style="font:smaller">{{f.name}} {{f.$error}} {{f.$errorParam}}</li>
</ul>
<div ngf-drop ngf-select ng-model="files" class="drop-box"
ngf-drag-over-class="'dragover'" ngf-multiple="true" ngf-allow-dir="true"
accept="image/*,application/pdf" ngf-select="uploadFiles($files)"
ngf-pattern="'image/*,application/pdf'"><img src="app/assets/img/cloud-computing.png" id="cloud" alt="" />Drag and drop files here to upload</div>
<div ngf-no-file-drop>File Drag/Drop is not supported for this browser</div>
<div id="moveStuff">
<p class="clickup">
-or click here to upload-
</p>
<div class="buttn" ngf-select="uploadFiles($files)" multiple accept="image/*">upload file</div>
</div>
</div>
</div>

Related

Angular, unable to get list of values from a webservice (JSON)

I'm trying to get a kids' list from JSON webservice, amid logging in I get a JSON response of name.... and the kids list for a specific doctor. I have the response in the console but for some reason when I try to display it in the HTML file I fail to do it.
Here's my kidsdetails.component.ts:
import {KidsService} from '../../service/kids.service';
import {ActivatedRoute, Router} from '#angular/router';
import {UserService} from '../../service/user.service';
import {MatDialog, MatDialogConfig} from '#angular/material/dialog';
import {environment} from '../../../environments/environment';
import {ToastrService} from 'ngx-toastr';
import {Doctor} from '../../model/doctor';
import {Kid} from '../../model/kid';
import {AppComponent} from '../../app.component';
#Component({
selector: 'app-details',
templateUrl: './kidsdetails.component.html',
styleUrls: ['./kidsdetails.component.css']
})
export class KidsdetailsComponent implements OnInit {
public kids : Array<Kid> = [];
// tslint:disable-next-line:variable-name max-line-length
constructor(private service: KidsService,
private route: ActivatedRoute,
private router: Router,
// tslint:disable-next-line:variable-name
private _auth: UserService,
private toastr: ToastrService) {
}
imageServer = `${environment.uploadWebServices}/upload/`;
doctors: [];
doctor;
notes: [];
selectedKid;
info = false;
game = false;
advancement = false;
personal = false;
array: Array<any>;
valueEditor = '';
games: Array<any>;
moyenne = 0;
pin = '';
isCollapsed = true;
doc:Array<Doctor>=[];
kid;
selectedParent;
ngOnInit(): void {
this.array = [];
for (let i = 0; i < 30; i++) {
this.array.push(i + 1);
}
this.getKidsList();
this.valueEditor = '';
}
getKidsList() {
this.kid=this.kids;
}
/* this.doctor = res;
this.doctors.forEach((doctor: Array<any>) => {
console.log('doc', doctor);
if (doctor['kidsinformation']) {
doctor['kidsinformation'].forEach((kid) => {
// el.photo
this.service.getKidImage(kid.photo).subscribe(
image => {
// console.log('image', image);
},
err => {
// console.warn('error', err);
if (err.status === 200) {
const img = err.error.text;
kid.photo = 'data:image/lpeg;base64,' + img;
// console.log("img", img)
}
}
);
});
}
});
},
(err) => {
console.log('err', err);
}
);*/
openKid(kid) {
this.games = [];
this.moyenne = 0;
console.log('kid', kid);
this.selectedKid = kid;
this.info = true;
this.game = false;
this.service.getUser(this.selectedKid.idUser).subscribe(
res => {
this.selectedParent = res;
}
)
this.service.getKidGames(kid.idUser, kid.id).subscribe(
(res) => {
console.log('games', res);
this.games = res as Array<any>;
this.games.forEach((el) => {
this.moyenne += el.gameScore;
});
this.moyenne = Math.floor(this.moyenne / this.games.length);
},
(err) => {
console.log('error occured', err);
}
);
document.querySelector('#m').classList.add('is-active');
}
openNotes() {
this.notes = [];
// this.selectedKid = kid;
/*this.service.getKidNotes(this.selectedKid.idUser, this.selectedKid.id).subscribe(
(res) => {
console.log('notes', res);
this.notes = res as [];
}, (err) => {
console.log('error occured', err);
});*/
this.router.navigateByUrl(`kids/${this.selectedKid.idUser}/${this.selectedKid.id}/notes`);
}
closePopup() {
document.querySelector('#m').classList.remove('is-active');
}
goToInfo() {
this.info = true;
this.game = false;
this.personal = false;
this.advancement = false;
}
goToGames() {
this.info = false;
this.game = true;
this.personal = false;
this.advancement = false;
}
goToAdvancement() {
this.info = false;
this.game = false;
this.personal = false;
this.advancement = true;
}
goToPersonalNotes() {
this.info = false;
this.game = false;
this.personal = true;
this.advancement = false;
}
logout() {
this._auth.logout();
this.router.navigateByUrl('/authentication/login');
}
addKid() {
document.querySelector('#add').classList.add('is-active');
}
onCreate() {
document.querySelector('#code').classList.add('is-active');
}
closeCodePopup() {
document.querySelector('#code').classList.remove('is-active');
}
savePin() {
console.log('pin is', this.pin);
this.service.consumeKid(this.pin).subscribe(
(res) => {
this.getKidsList();
this.pin = '';
this.toastr.success('The child was added successfully');
this.closeCodePopup();
},
(err) => {
this.toastr.error('A problem occurred while adding the child');
// console.log(err);
}
);
}
getEditorText() {
// kidId , text
// return this.http.post("url", { }, { headers : json + authorization })
console.log('text ', this.valueEditor);
if (this.valueEditor !== '') {
this.service.addNote(this.selectedKid.id, this.selectedKid.idUser, this.valueEditor).subscribe(
res => {
console.log(' saved note , res => ', res);
this.toastr.success('Note was added successfully');
},
err => {
console.log('error saving notes', err);
this.toastr.error('There was an error adding the note');
}
);
}
}
updateInput(e) {
this.valueEditor = e;
}
showAllNotes() {
// tslint:disable-next-line:no-unused-expression
this.router.navigate['kid/notes'];
}
toggleCollapse() {
this.isCollapsed = !this.isCollapsed;
}
}
This is my kidsdetails.component.html
<div class="row mt-4">
<div class="col-md-4">
<a (click)="logout()"
style="padding:15px 20px; border-radius: 50%; background-color: #c8c8c8; color: white; cursor: pointer">
<i class="fa fa-power-off"></i>
</a>
</div>
<div class="col-md-4 mb-5">
<p class="text-center h2" style="color: #EF6E28; font-weight: 700">KIDS LIST</p>
</div>
<!--div class="col-md-4" style="display: flex">
<div style="margin: 0 auto"></div>
<div>
<a
style="padding:15px 20px; border-radius: 50%; background-color: #EF6E28; color: white; cursor: pointer">
<i class="fa fa-plus"></i>
</a>
</div>
</div-->
<div class="col-md-4" style="display: flex">
<div style="margin: 0 auto"></div>
<button id="circle" style="color: white; cursor: pointer"
mat-raised-button (click)="onCreate()">
<i class="fa fa-plus"></i>
</button>
</div>
</div>
<div class="row mt-3">
<div class="col-md-1"></div>
<div class="col-md-10">
<!--div [(ngModel)]="doctor.Kids"></div-->
<div *ngFor="let k of kids" class="col-md-6">
<!--pre>
{{kids | json}}
</pre-->
<!--a href="/kidsinformation/kid/{{doctor.id}}/{{kid.id}}"-->
<a (click)="openKid(k)" style="cursor: pointer">
<div class="card mb-3" style="max-width: 540px;">
<div class="row no-gutters">
<div class="col-md-4">
<!--img src="{{imageServer}}{{kid.photo}}" style="height: 100%" class="card-img" alt="..."-->
<img *ngIf="k.gender == 1" src="assets/Girl.png" style="height: 100%" class="card-img" slot="start">
<img *ngIf="k.gender == 0" src="assets/Boy.png" style="height: 100%" class="card-img" slot="start">
</div>
<div class="col-md-8">
<div class="card-body">
<div style="display: flex">
<h3 class="card-title text-info"><strong>{{k.nickName}}</strong></h3>
<div style="margin: 0 auto"></div>
<h3 class="card-title text-secondary">{{k.age}}</h3>
</div>
<p class="card-text" style="margin-bottom: 0 !important"><small class="text-muted"></small></p>
<div style="display: flex">
<p class="card-text" style="margin-bottom: 0 !important;">
<!--Parent phone number here -->
<small class="text-muted"></small>
</p>
<div style="margin: 0 auto"></div>
<p class="card-text" style="margin-bottom: 0 !important;">
<small class="text-right gender girl" *ngIf="k.gender == 1">Girl</small>
<small class="text-right gender boy" *ngIf="k.gender == 0">Boy</small>
</p>
</div>
</div>
</div>
</div>
</div>
</a>
</div>
</div>
</div>
</div>
<div class="col-md-1"></div>
<div class="modal" id="m">
<div class="modal-background" (click)="closePopup()"></div>
<div class="modal-card">
<div class="container" style="background-color: #E9E9E9">
<div class="row">
<div class="col-md-12">
<img style="width: 80px; display: block; margin: auto" src="assets/logoSghartoon.png" alt="">
</div>
</div>
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-10">
<div class="tabs">
<div id="tab3" class="tab">
<ul style="font-size: 1.5rem" class="nav nav-tabs">
<li class="tabulation tab-info mr-3"><a (click)="goToInfo()">Kid's info</a></li>
<li class="tabulation tab-game mr-3"><a (click)="goToGames()">Games</a></li>
<!--li class="tabulation tab-advance mr-3"><a (click)="goToAdvancement()">Advancement</a></li-->
<li class="tabulation tab-personal mr-3"><a (click)="goToPersonalNotes()">Personal notes</a></li>
</ul>
<!-- Kid's info Start-->
<div class="tab-content" *ngIf="info">
<div class="container" style="margin-top: -1px">
<div class="row">
<div class="col-md-12 mt-5 pl-5 pr-2">
<div class="row pb-2">
<div class="col-md-4">
<div>
</div>
<!--img width="250px" src="{{imageServer}}{{selectedKid.photo}}" alt=""-->
<img *ngIf="selectedKid.gender == 1" src="assets/Girl.png" style="height: 100%"
class="card-img" slot="start">
<img *ngIf="selectedKid.gender == 0" src="assets/Boy.png" style="height: 100%"
class="card-img" slot="start">
</div>
<div *ngIf="selectedKid" class="col-md-8">
<div class="card-body">
<div style="display: flex">
<h3 class="card-title h1 text-info">
<strong>{{selectedKid.nickName}}   </strong>
<strong style="font-size: 2.5rem !important;" class="text-right h1 gender girl"
*ngIf="selectedKid.gender == 1">Girl</strong>
<strong style="font-size: 2.5rem !important;" class="text-right h1 gender boy"
*ngIf="selectedKid.gender == 0">Boy</strong>
</h3>
<div style="margin: 0 auto"></div>
<h3 class="card-title text-secondary" style="font-size: 2rem">
<strong>{{selectedKid.age}} Years old</strong>
</h3>
</div>
<p class="card-text" style="margin-bottom: 0 !important; font-size: 2rem; color: gray">
</p>
<div style="display: flex">
<div style="margin: 0 auto"></div>
<p class="card-text" style="margin-bottom: 0 !important;">
</p>
<!--Parent phone number here -->
<div>
<small class="phone-number">
<i id="phone" class="fa fa-phone"></i>
Phone number: {{selectedParent.phoneNumber}} </small>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Kid's info End-->
<!-- Games Start-->
<div class="tab-content" *ngIf="game" style="border-bottom-left-radius: 10px; background-color: #EF6E28">
<div class="container" style="margin-top: -1px">
<div class="row">
<div class="col-md-12 mt-5 pr-2">
<div class="row pb-2">
<div class="col-md-2"
style="margin-top: auto; margin-bottom: auto; padding-right: 0; padding-left: 0">
<div style="text-align: center">
<span class="h1 text-center text-light"
style="font-size: 3rem"> <strong>{{moyenne}}</strong></span>
</div>
<div style="text-align: center">
<span class="h3 text-center text-light"><strong>Total Score</strong></span>
</div>
</div>
<div class="col-md-10">
<div class="card-body card-body-modal">
<div style="background-color: white; padding: 20px; border-radius: 10px"
class="table-wrapper-scroll-y my-custom-scrollbar">
<table class="table table-striped mb-0">
<thead style="background-color: #E9E9E9; border-radius: 25px">
<th>Game name</th>
<!--th>Type</th-->
<th>Timing</th>
<th>Score</th>
<th>Action</th>
</thead>
<tbody>
<tr *ngFor="let game of games" style="background-color: #FFFFFF; color: #EF6E28">
<td class="first_td"> {{game.idTestGame | gameName}} </td>
<!--td>{{game}}</td-->
<td>{{game.timeScore}}sec</td>
<td class="last_td"> {{game.gameScore}} </td>
<td *ngIf="isCollapsed">
<button
(click)="toggleCollapse()" class="btn btn-outline-warning">Show more details
</button>
</td>
<td *ngIf="!isCollapsed">
<button
(click)="toggleCollapse()" class="btn btn-outline-warning">Show less details
</button>
</td>
<div *ngIf="!isCollapsed">
<img src="assets/gameScreenshot.PNG" style="height: auto" class="card-img">
</div>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Games End-->
<!-- advancement Start-->
<!--div class="tab-content" *ngIf="advancement"
style="border-bottom-left-radius: 10px; margin-bottom: -1px ;background-color: #00A5D2">
</div-->
<!-- advancement End-->
<!-- Presonal notes start -->
<div class="tab-content" *ngIf="personal"
style="border-bottom-left-radius: 10px; background-color: #ffdf00">
<div class="container-fluid" style="margin-top: -1px">
<div class="row">
<div class="col-md-12 mt-2 mb-2 pr-2 pl-2">
<div class="container-fluid" style="background-color:#E9E9E9; height: 345px ;border-radius: 10px">
<div class="row">
<div class="col-md-2" style="margin-top: auto; margin-bottom: auto">
<button style="margin-left: 10px; border-radius: 10px;" kendoButton (click)="openNotes()"
[primary]="true">Show all notes
</button>
</div>
<div class="col-md-10">
<div>
<kendo-editor [value]="valueEditor" (valueChange)="updateInput($event)"
style="height: 300px; margin-top: 5px"></kendo-editor>
</div>
<div style="display: flex">
<div style="margin-left: auto; margin-right: auto"></div>
<div>
<button style="border-radius: 10px;margin-top:5px; margin-bottom: 20px" kendoButton
[primary]="true" [disabled]="valueEditor==''" (click)="getEditorText()"> getText
</button>
</div>
</div>
</div>
<div *ngFor="let note of notes">
<div>
<pre> {{note | json }} </pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Presonal notes End -->
</div>
</div>
</div>
</div>
<!-- Child add via pin code start -->
<div class="modal" id="code">
<div class="modal-background" (click)="closeCodePopup()"></div>
<div class="modal-card" style="width: 40%">
<header class="modal-card-head">
<p class="modal-card-title">Add a kid</p>
<button class="close" (click)="closeCodePopup()"><i class="far fa-times-circle"></i></button>
</header>
<form #f="ngForm">
<section class="modal-card-body">
<div class="form-group">
<label for="">Pin code</label>
<input type="text" #p="ngModel" required [(ngModel)]="pin" name="pin" placeholder="PIN" class="form-control">
<div class="text-danger" *ngIf="p.touched && p.invalid"> Pin code is required!</div>
</div>
</section>
<footer class="modal-card-foot">
<button class="btn " [disabled]="f.invalid" style="background-color: #EF6E28; color: white" (click)="savePin()">
Save changes
</button>
<button class="btn" (click)="closeCodePopup()">Cancel</button>
</footer>
</form>
</div>
</div>
<!-- Child add via pin code end -->
This is the Doctors model:
export class Doctor {
public createdAt:string ;
public firstName:string;
public id: string;
public kids: Array<Kid>;
public lastName:string;
public login: string;
public mail: string;
public password: string;
public phoneNumber:string;
public photo: string;
public token: string;
public updatedAt: string;
}
This is the service: I get the doctors by the method getUsers() because I don't have direct access to the kid's list:
import {HttpClient, HttpHeaders} from '#angular/common/http';
import {environment} from '../../environments/environment';
import {UserService} from './user.service';
import {Router} from '#angular/router';
#Injectable({
providedIn: 'root'
})
export class KidsService {
private readonly proxy: string = environment.usersWebServices;
private readonly proxyTrace: string = environment.traceWebServices;
private readonly imageServer: string = environment.uploadWebServices;
constructor(private http: HttpClient,
private service: UserService,
private route: Router) { }
private get JsonType() {
const headers = new HttpHeaders({ Authorization : 'Bearer ' + localStorage.getItem('access') });
// headers.append({'Authorization': ''});
return headers;
}
public getUsers() {
return this.http.get(`${this.proxy}/doctor`, { headers : this.JsonType });
}
getUser(id) {
// authentication/id
return this.http.get(`${this.proxy}/user/${id}`, { headers : this.JsonType });
}
onLogout() {
localStorage.removeItem('token');
this.route.navigateByUrl('/authentication/login');
}
getKidGames( idUser, idKid ) {
return this.http.get(`${this.proxyTrace}/dataoutput/evaluation/${idUser}/${idKid}`, { headers : this.JsonType });
}
consumeKid(pinCode) {
const idDoctor = this.service.getUserDetails().unique_name;
return this.http.get(`${this.proxy}/kidcode/consume/${pinCode}/${idDoctor}`);
}
addNote( idKid, idUser, text ) {
const obj = { text , idKid , idUser};
return this.http.post(`${this.proxy}/doctornote`, obj, { headers : this.JsonType });
}
getKidNotes(idUser, idKid) {
return this.http.get(`${this.proxy}/doctornote/bykid/${idUser}/${idKid}`, {headers : this.JsonType});
}
getKidImage(id) {
return this.http.get(`${this.imageServer}/upload/${id}`, {headers : this.JsonType});
}
}

Highlighting text in AngularJs

<header class="layer-bottom">
<div class="container">
<div class="row">
<div class="col-md-2"
style="padding: 0;">
<img src="resources/logo.png"
style="width: 60%;">
</div>
<div class="col-md-8 navBar">
<span ng-click="ads();" style="color: #fff;">
Ad on bill
</span>
<span class="divider">|</span>
<span ng-click="visibilityMessages();" style="color: #fff;">
Messages
</span>
<span class="divider">|</span>
<span ng-click="visibility();" style="color: #fff;">
Visibility
</span>
<span class="divider">|</span>
<span ng-click="pricePromotions()" style="color: #fff;">
Price Promotions
</span>
</div>
<div class="col-md-2" style="margin-top: 1.5%">
<!--<i class="fa fa-2x fa-bars" aria-hidden="true">-->
<span ng-bind="userObj.companyName"></span>
<button type="button" class="btn btn-default" ng-click="logout();">
<span class="glyphicon glyphicon-log-out"></span> Log out
</button>
</div>
</div>
</div>
</header>
I have a doubt in highlighting a text.Initially all the headings have the color specified it the style.When i click AdOnBill , color or font-size has to be changed.How can I do that?
Controller
scope.ads = function() {
location.path("/dashboard/messages");
};
scope.visibilityMessages = function() {
location.path("/dashboard/visibility_messages");
};
You can use ng-class or ng-style for this case, such as (ng-class):
<span ng-click="ads();" class="default" ng-class="{'change': isChangeStyle}">
Ad on bill
</span>
Controller:
$scope.isChangeStyle = false;
//
$scope.ads = function () {
$scope.isChangeStyle = true;
};
CSS:
.default {
color: #fff;
}
.change {
color: #000;
font-size: 20px;
}
You can use ng-class:
<span ng-class="{className: condition}">Ad on bill</span>
This JSFiddle demo shows well the use you want to make of it in your specific case.
<a ng-click="setRed()">Set "Ad on bill" red!</a>
<span ng-class="{red: isRed}">Ad on bill</span>
Where setRed() just do:
$scope.setRed = function() {
$scope.isRed = true;
}
You can use ng-style for this
The ngStyle directive allows you to set CSS style on an HTML element conditionally.
https://docs.angularjs.org/api/ng/directive/ngStyle
<span ng-click="ads();" style="color: #1ff;" ng-style="myObj">
Ad on bill
</span>
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body ng-app="myApp" ng-controller="myCtrl">
<span ng-click="ads();" style="color: #1ff;" ng-style="myObj">
Ad on bill
</span>
<br><br><br><br>
<span ng-click="visibility();" style="color: black" ng-style="myObj">
Remaining Tabs
</span>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.ads = function(){
$scope.myObj = {
"color" : "white",
"background-color" : "coral",
"font-size" : "30px",
"padding" : "20px"
}
}
$scope.visibility = function(){
$scope.myObj = {
"color" : "black",
}
}
});
</script>
</body>
</html>
PLEASE RUN THE ABOVE SNIPPET
HERE IS THE WORKING DEMO
EDIT:
In the remaining methods,add
$scope.myObj = {
"color" : "#fff",
}
<span ng-click="visibility($event);" class="headerTabs" id="visibility">
Visibility
</span>
<span ng-click="pricePromotions($event);" class="headerTabs" id="pricePromotion">
Price Promotions
</span>
scope.visibility = function($event){
var tabs = document.getElementsByClassName("headerTabs");
for(var i = 0;i < tabs.length;i++) {
if($event.target.id === tabs[i].id)
$event.target.style.color = "#fff";
else
tabs[i].style.color = "";
}
};
This one worked :)

Target specific object index/id out of ng-repeat

I have a form set up that takes values and saves them into an object in a firebase array. I used ng-repeat to display each object in that array in a "dashboard" page. I want to be able to alter the specific object that gets created via checkboxes. I cannot figure out how to get the specific object.
var app = angular.module('app', ['ngRoute','firebase','ngMaterial']);
app.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/second', {
templateUrl: 'templates/second.html',
controller: 'homeCTRL'
})
.when('/dashboard', {
templateUrl: 'templates/dashboard.html',
controller: 'homeCTRL'
})
.when('/vehicles', {
templateUrl: 'templates/vehicles.html',
controller: 'homeCTRL'
})
.otherwise({
redirectTo: '/dashboard'
});
}]);
//controllers
app.controller('homeCTRL', ['$scope', '$log','$firebaseArray', function($scope,$log,$firebaseArray) {
var ref = new Firebase("https://asgtodo.firebaseio.com");
$scope.newItem = '';
$scope.FBproject= $firebaseArray(ref.child('project'));
$scope.FBhistory = $firebaseArray(ref.child('history'));
$scope.projectName = '';
$scope.dateStart = '';
$scope.dateEnd = '';
$scope.signChecked = '';
$scope.paintChecked = '';
$scope.blastChecked = '';
$scope.labelChecked = '';
$scope.yellowMacro = '';
$scope.redMacro = '';
$scope.otherPaint = '';
$scope.pipeFootage = '';
$scope.maxHeight = '';
$scope.liftSmall = '';
$scope.liftLarge = '';
$scope.liftBoom = '';
$scope.pipeCompleted = false;
$scope.addItem = function() {
$scope.FBproject.$add({
projectName: $scope.projectName,
dateStart: $scope.dateStart,
dateEnd: $scope.dateEnd,
signChecked: $scope.signChecked,
paintChecked: $scope.paintChecked,
blastChecked: $scope.blastChecked,
labelChecked: $scope.labelChecked,
yellowMacro: $scope.yellowMacro,
redMacro: $scope.redMacro,
otherPaint: $scope.otherPaint,
pipeFootage: $scope.pipeFootage,
maxHeight: $scope.maxHeight,
liftSmall: $scope.liftSmall,
liftLarge: $scope.liftLarge,
liftBoom: $scope.liftBoom,
pipeCompleted: $scope.pipeCompleted
});
$scope.projectName = '';
$scope.dateStart = '';
$scope.dateEnd = '';
$scope.signChecked = '';
$scope.paintChecked = '';
$scope.blastChecked = '';
$scope.labelChecked = '';
$scope.yellowMacro = '';
$scope.redMacro = '';
$scope.otherPaint = '';
$scope.pipeFootage = '';
$scope.maxHeight = '';
$scope.liftSmall = '';
$scope.liftLarge = '';
$scope.liftBoom = '';
};
$scope.changePipe = function(x){
$scope.index = $scope.FBproject.indexOf(x);
};
$scope.rmList = function(item) {
//get index of displayHold
$scope.index = $scope.FBproject.indexOf(item);
//add it to historylist
$scope.FBhistory.$add($scope.FBproject[$scope.index]);
$scope.FBproject.$remove($scope.FBproject[$scope.index]);
};
$scope.modalItem = function(item){
return null;
};
}]);
app.controller('secondCTRL', ['$scope', function($scope) {
}]);
Here is the html
<!-- MODAL BUTTON -->
<div style="margin-top: 6em;">
<div class="row animated shake">
<div class="col s6 m5 l5">
<center>
<a class="btn-floating btn-large waves-effect waves-dark blue modal-trigger" id="modal" href="#modal1">
<i class="material-icons">add</i>
</a>
</center>
</div>
</div>
</div>
<!-- MODAL -->
<div id="modal1" class="modal bottom-sheet white" style="height: 100%; opacity: 0.8">
<div class="modal-content white blue-text">
<div class="row">
<form>
<div class="row animated rollIn">
<div class="input-field col s12 m6 l6">
<input id="projName" type="text" ng-model="projectName">
<label id="projNameLabel">Project Name</label>
</div>
<div class="input-field col s12 m3 l3">
<label id="projDateLabel">Start Date</label>
<input id="projDate" type="date" class="datepicker " ng-model="dateStart">
</div>
<div class="input-field col s12 m3 l3">
<label id="projDateLabel">End Date</label>
<input id="projDate" type="date" class="datepicker" ng-model="dateEnd">
</div>
</div>
<div class="row">
<div class="col s12 m2 l2">
<center>
<form action="#">
<p class="padBoxes">
<input type="checkbox" id="Signs" class="Materialize.showStaggeredList('#test')" ng-model="signChecked"/>
<label for="Signs">Signs</label>
</p>
<p class="padBoxes">
<input type="checkbox" id="Paint" ng-model="paintChecked"/>
<label for="Paint">Paint</label>
</p>
<p ng-show="paintChecked" style="margin-left: 15px;" class="padBoxes">
<input type="checkbox" id="Blast" ng-model="blastChecked"/>
<label for="Blast">Blast</label>
</p>
<p class="padBoxes">
<input type="checkbox" id="Labels" ng-model="labelChecked"/>
<label for="Labels">Labels</label>
</p>
</form>
</center>
</div>
<div class="col s12 m3 l3 z-depth-5" style="margin-right: 10px;" ng-show="paintChecked">
<center class="animated fadeIn">
<form action="#">
<div class="indigo z-depth-2" style="height: 60px;margin-bottom: 30px;">
<p>
<h5 style="color: white; padding: 15px; float:left; font-weight: condensed">Paint</h5>
</p>
</div>
<p class="range-field padBoxes">
<label for="Labels">Yellow 646 Paint</label>
<input type="range" id="test5" min="0" max="50" ng-model="yellowMacro"/>
</p>
<p class="range-field padBoxes">
<label for="Labels">Red 646 Paint</label>
<input type="range" id="test5" min="0" max="50" ng-model="redMacro"/>
</p>
<p class="input-field padBoxes">
<input id="projName" type="text" ng-model="otherPaint">
<label>Other</label>
</p>
</form>
</center>
</div>
<div class="col s12 m2 l3 z-depth-3" style="margin-right: 10px;" ng-show="signChecked">
<form action="#">
<div class="col s12 animated fadeIn">
<center>
<div class="red z-depth-2" style="height: 60px;margin-bottom: 30px;">
<p>
<h5 style="color: white; padding: 15px; float:left; font-weight: condensed">Signs</h5>
</p>
</div>
<p class="input-field">
<input id="projName padBoxes" type="text" ng-model="pipeFootage">
<label>Pipe Footage</label>
</p>
<p class="range-field padBoxes">
<label for="Labels ">Max Height</label>
<input type="range" id="test5" min="0" max="50" ng-model="maxHeight"/>
</p>
</center>
</div>
</form>
</div>
<div class="col s12 m2 l2 " style="margin-right: 10px;" ng-show="signChecked || labelChecked">
<center>
<p >
<input type="checkbox" id="liftSmall" ng-model="liftSmall"/>
<label for="liftSmall">Lift 3246</label>
</p>
<p >
<input type="checkbox" id="liftLarge" ng-model="liftLarge"/>
<label for="liftLarge">Lift 4069</label>
</p>
<p >
<input type="checkbox" id="liftBoom" ng-model="liftBoom"/>
<label for="liftBoom">Lift BOOM!</label>
</p>
</center>
</div>
</div>
</div>
</form>
</div>
<div class="input-field col s12 m2 l2 padBoxes" style="margin: -50px;">
<center>
<a href="#!" class="modal-action modal-close waves-effect waves-dark btn-flat z-depth-2">
<i class="material-icons" style="font-size: 3em;">close</i>
</a>
<a class="btn-floating btn-large waves-effect waves-dark blue z-depth-2" onclick="Materialize.toast('Project Added', 4000)" ng-click="addItem()">
<i class="material-icons">add</i>
</a>
</center>
</div>
</div>
<!-- FBproject -->
<div class="container row" style="margin-top: 4em; ">
<ul class="collapsible" data-collapsible="accordion">
<li ng-repeat="x in FBproject track by $index">
<div class="collapsible-header waves-effect waves-dark">
<div class="col s2 m2 l1">
<center>
<i class="material-icons">folder-open</i>
</center>
</div>
<div class="col s5 m2 l2">
{{x.projectName}}
</div>
<div class="col s12 m5 l4">
<center>
<div class="chip">Signs</div>
<div class="chip">Paint</div>
<div class="chip">Labels</div>
</center>
</div>
</div>
<div class="collapsible-body">
<div class="row">
<center>
<form action="#">
<p>
<input type="checkbox" ng-model="{{}}" />
<label for="pipe">Pipe Ordered</label>
</p>
<p>
<input type="checkbox" id="{{x.index}}"/>
<label for="hotel">Hotel</label>
</p>
<p>
<input type="checkbox" id="{{x.index}}"/>
<label for="lifts">
<h7>lifts</h7>
</label>
</p>
<a class="btn-floating btn-large waves-effect waves-dark red" ng-click="rmList(x)">
<i class="material-icons">delete_forever</i>
</a>
</form>
</center>
</div>
</li>
</ul>
</div>
<script>
$(document).ready(function() {
$('.collapsible').collapsible({accordion: false});
$('.modal-trigger').leanModal({dismissible: true, opacity: .50, in_duration: 300, out_duration: 200});
$('.datepicker').pickadate({selectMonths: true, selectYears: 15, container: 'body'});
$('select').material_select({container: 'body'});
$(".button-collapse").sideNav();
});
</script>
index.html
<!DOCTYPE HTML>
<html ng-app="app">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/css/materialize.min.css">
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/angular_material/1.1.0-rc2/angular-material.min.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.1/animate.min.css">
<link href="//fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/js/materialize.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-route.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-animate.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-aria.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-messages.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angular_material/1.1.0-rc2/angular-material.min.js"></script>
<script src="//cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
<script src="//cdn.firebase.com/libs/angularfire/1.2.0/angularfire.min.js"></script>
<script src="app.js"></script>
<link rel="stylesheet" href="main.css"/>
</head>
<body ng-cloak>
<div>
<div class="fixed-action-btn horizontal click-to-toggle" style="top: 5px; center: 24px;">
<a class="btn-floating waves-effect waves-dark btn-large">
<i class="material-icons">menu</i>
</a>
<ul>
<li>
<a href="#/dashboard" class="btn-floating waves-effect waves-dark btn-large yellow darken-1">
<i class="material-icons">dashboard</i>
</a>
</li>
<li>
<a href="#/second" class="btn-floating waves-effect waves-dark blue btn-large green darken-1">
<i class="material-icons">find_in_page</i>
</a>
</li>
<li>
<a href="#/vehicles" class="btn-floating waves-effect waves-dark btn-large red darken-1">
<i class="material-icons">directions_car</i>
</a>
</li>
</ul>
</div>
</div>
<div ng-view></div>
</body>
</html>
section is question?
<div class="collapsible-body">
<div class="row">
<center>
<form action="#">
<p>
<input type="checkbox" ng-model="x.pipeCompleted{{index}}"/> <!-- what do I put here ?? to get the specific object-->
<label for="pipe">Pipe Ordered</label>
</p>
<p>
Try this:
<input type="checkbox" ng-model="pipeCompleted[$index]"/>

Bootstrap-UI local images not showing

I'm using AngularJS with Bootstrap-UI and I'm using the carousel directive. When I have the images in my Ctrl pointing to a website (lorumpixel.com) the images are appearing; however, I have images that I want to place into the site.
<div ng-controller="CarouselCtrl">
<div carousel interval="3000">
<div slide ng-repeat="slide in slides" active="slide.active">
<img ng-src="{{slide.image}}">
<div class="carousel-caption animated slideInLeft">
<h2>Slide {{$index}}</h2>
<p>{{slide.text}}</p>
</div>
</div>
</div>
</div>
and my Controller
'use strict';
angular.module('angularApp')
.controller('CarouselCtrl', function ($scope) {
$scope.slides = [];
$scope.slides.push({text: '', image: 'images/bg-2.jpg'});
$scope.setActive = function(idx) {
$scope.slides[idx].active=true;
};
});
I'm hoping to get this website up by the end of the week so any help is greatly appreciated. Thanks in advance.
roof.controller.js
angular.module('monsterApp').controller('CarouselCtrl', function ($scope) {
$scope.myInterval = 5000;
$scope.noWrapSlides = false;
var slides = $scope.slides = [];
$scope.addSlide = function() {
var newWidth = 1500 + slides.length + 1;
slides.push({
url: "http://res.cloudinary.com/dqa0blkfn/image/upload/v1436283760/monster-head_tnxloc.jpg",
/* url: '//placekitten.com/' + newWidth + '/300', */
text: [' ',' ',' ',' '][slides.length % 4] + ' ' +
[' ', ' ', ' ', ' '][slides.length % 4]
});
};
roof.html
<div ng-controller="CarouselCtrl">
<div style="height: 305px">
<carousel interval="myInterval" no-wrap="noWrapSlides">
<slide ng-repeat="slide in slides" active="slide.active">
<img ng-src="{{slide.url}}" style="margin:auto;">
<div class="carousel-caption">
<h4>Slide {{$index}}</h4>
<p>{{slide.text}}</p>
</div>
</slide>
</carousel>
</div>
<div class="row">
<div class="col-md-6">
<button type="button" class="btn btn-info" ng-click="addSlide()">Add Slide</button>
<div class="checkbox">
<label>
<input type="checkbox" ng-model="noWrapSlides">
Disable Slide Looping
</label>
</div>
</div>
<div class="col-md-6">
Interval, in milliseconds: <input type="number" class="form-control" ng-model="myInterval">
<br />Enter a negative number or 0 to stop the interval.
</div>
</div>
</div>

Adding element to el in backbone

This is source code that viewing from my web page :
<div id="webcontainer">
<div id="webheader"></div>
<div id="webbody">
<div id="webbodycontainer"></div>
</div>
<div id="webfooter"></div>
</div>
Here is the view :
var RegisterView = Backbone.View.extend({
el : $("#webbodycontainer"),
initialize : function(){
},
events : {
'click #register' : 'registerUser'
},
registerUser : function(){
alert("hi");
},
render : function(){
$("#webheader").html(headerTem);
$("#webfooter").html(footerTem);
var _registerDes = _.template(RegisterDescriptionTem);
this.$el.append(_registerDes);
}
});
return RegisterView;
_registerDes content is shown in the webpage but not in a DOM, So click event on a #register button is not fired. Have I missed something?
Here is RegisterDescriptionTem template :
<div class="registerleftpanel">
//....
</div>
<div id="rightpanel" style="float:right; padding-right:10px;">
<div id="registerPanel" style="width: 528px;">
<div class="cartheadertitle loginheadertitle">Register New Account</div>
<br>
<form id="registerForm" style="margin-bottom: 10px;">
//......
<div style="position: relative; float: left; left: 90px; top: -3px;">
<input type="button" value="Register" class="btn" id="register">
</div>
</form>
</div>
</div>

Resources