Adding element to el in backbone - backbone.js

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>

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});
}
}

How can I make ng-click work in AngularJs

I added some ng-click events for buttons but when I try to click buttons, test() function won't fire. I did everything to fix that but I couldn't.
<div ng-controller="bilgiyarismasiCtrl" ng-repeat="x in sorular">
<div class="row text-center" style="margin: 50px 250px 50px 250px;">
<div class="col-md-12" style="padding:90px; background-color:gray; color:white;">
{{ x.SORU_ICERIGI }}
</div>
<div class="col-md-6" style="padding:50px; background-color:white;">
<button ng-click="test()" class="btn btn-primary btn-lg">{{ x.A_SIKKI }}</button>
</div>
<div class="col-md-6" style="padding:50px; background-color:white;">
<button ng-click="test()" class="btn btn-primary btn-lg">{{ x.B_SIKKI}}</button>
</div>
</div>
<br /><br /><br />
</div>
Angular code:
var app = angular.module("module", ["ngRoute"]);
app.config(function ($routeProvider) {
$routeProvider
.when("/", {
templateUrl: "bilgiyarismasi.html",
controller: "bilgiyarismasiCtrl"
});
});
app.controller("bilgiyarismasiCtrl", function ($scope, $http) {
$http.get("http://localhost:53438/api/BilgiYarismasi/GetSorular")
.then(function (response) {
$scope.sorular = response.data;
});
$scope.test = function () {
console.log(1)
}
});
FYI, Your code above is not invoking controller, due to this you are not able get output by clicking on any of your buttons.
Use below code :
var ngApp = angular.module('app', []);
ngApp.controller('bilgiyarismasiCtrl',function($scope, $http){
$scope.sorular = [];
/* $http.get("http://localhost:53438/api/BilgiYarismasi/GetSorular")
.then(function (response) {
$scope.sorular = response.data;
}); */
$scope.test = function () {
console.log('test')
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="app">
<div ng-controller="bilgiyarismasiCtrl">
<div >
<div class="row text-center" style="margin: 50px 250px 50px 250px;">
<div class="col-md-12" style="padding:90px; background-color:gray; color:white;">
{{ x.SORU_ICERIGI }}
</div>
<div class="col-md-6" style="padding:50px; background-color:white;">
<button ng-click="test()" class="btn btn-primary btn-lg">{{ 'x.A_SIKKI' }}</button>
</div>
<div class="col-md-6" style="padding:50px; background-color:white;">
<button ng-click="test()" class="btn btn-primary btn-lg">{{' x.B_SIKKI'}}</button>
</div>
</div>
<br /><br /><br />
</div>
</div>
</div>
You have not included ng-app in your template file.
I have created a demo, can you please have a look.
Hope this helps you.

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 :)

Angularjs ngFileUpload adding new file overwrites last one

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>

AngularJS context menu to show closest next div only

How to show the context menu related div on my on click function? How to find the closest next div class and make visible on click on the button event, instead of showing all the div having the same classes.
Please note below my HTML and js also the fiddle link for reference:
http://jsfiddle.net/4WK7R/274/
HTML:
<div ng-app>
<div ng-controller="MyCtrl">
<div class="row">
<button id="mybutton" ng-click="showAlert()">Click me</button>
<div ng-show="myvalue" class="ng-cloak">11111111</div>
</div>
<div class="row">
<button id="mybutton" ng-click="showAlert()">Click me</button>
<div ng-show="myvalue" class="ng-cloak">22222222</div>
</div>
<div class="row">
<button id="mybutton" ng-click="showAlert()">Click me</button>
<div ng-show="myvalue" class="ng-cloak">333333333</div>
</div>
</div>
</div>
JS:
function MyCtrl($scope) {
$scope.myvalue = false;
$scope.showAlert = function(){
$scope.myvalue = true;
};
}
This is what you want i think:
<div ng-app>
<div ng-controller="MyCtrl">
<div class="row">
<button id="mybutton" ng-click="showAlert('div1')">Click me</button>
<div ng-show="div1" class="ng-cloak">11111111</div>
</div>
<div class="row">
<button id="mybutton" ng-click="showAlert('div2')">Click me</button>
<div ng-show="div2" class="ng-cloak">22222222</div>
</div>
<div class="row">
<button id="mybutton" ng-click="showAlert('div3')">Click me</button>
<div ng-show="div3" class="ng-cloak">333333333</div>
</div>
</div>
function MyCtrl($scope) {
$scope.showAlert = function(show){
//edited
$scope[show] ? $scope[show] = false: $scope[show]= true;
//$scope[show] = true;
};
}
Tabs:
function MyCtrl($scope) {
$scope.tabs = [{
title: "tab1",
show: true
}, {
title: "tab2",
show: false
}, {
title: "tab3",
show: false
}, ]
$scope.tabAction = function(tab) {
angular.forEach($scope.tabs, function(tab) {
tab.show = false;
});
tab.show ? tab.show = false : tab.show = true;
}
};
<div ng-app>
<div ng-controller="MyCtrl">
<div ng-repeat="tab in tabs">
<div ng-show="tab.show">{{tab.title}}</div>
<button ng-hide="tab.show" ng-click="tabAction(tab)">
open {{tab.title}}
</button>
<hr>
</div>
</div>

Resources