I want to assign different hrefs to different tds within a table that autogenerates said tds from data pulled from firestore.
This is my oferta.js, I can retrieve the data from firestore without a problem but I don't really have any idea on how to assign a different href to the td "titulo", I tried using anchors but this results in establishing the same URL in each consecutive td, what can I do to circumvent this problem?, thanks in advance!
const ofertaList = document.querySelector('#ofertaLista');
const setupOferta = (data) => {
let html = '';
data.forEach(doc => {
const oferta = doc.data();
const td =`
<tr>
<td>${oferta.titulo}</td>
<td>${oferta.tipo}</td>
<td>${oferta.fecha}</td>
<td>${oferta.areaConocimiento}</td>
<td>${oferta.cupoLimitado}</td>
</tr>
`;
html += td
});
ofertaList.innerHTML = html;
}
db.collection('oferta').get().then((snapshot) =>{
setupOferta(snapshot.docs)
});
EDIT
This is my oferta.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Oferta</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css?family=Questrial&display=swap" rel="stylesheet">
<!-- Bulma Version 0.8.x-->
<link rel="stylesheet" href="https://unpkg.com/bulma#0.8.0/css/bulma.min.css" />
<link rel="stylesheet" type="text/css" href="css/login.css">
</head>
<body>
<section class="hero is-info is-bold is-fullhd">
<div class="hero-body">
<nav class="navbar is-info">
<a class="navbar-item" href="https://balsamiq.cloud/sb17nzh/p8yk3ts/r2278">
<img src="https://bulma.io/images/bulma-logo.png" width="112" height="28">
</a>
<div class="container">
<div class="navbar-brand">
<h1 class="title">
CAEDI
</h1>
</div>
</div>
</nav>
</div>
</section>
<div id="main">
<section class="hero is-light">
<div class="hero-body">
<div class="container">
<h1 class="title">
Oferta
</h1>
</div>
</div>
</section>
<div class="container">
<input class="input" type="text" name="" id="textBoxSearch" placeholder="Buscar" />
<br /><br />
</div>
<section class="section">
<div class="container">
<div class="columns">
<div class="column is-12">
<div>
<table id="fullfeatures" class="table is-striped is-bordered" cellspacing="0" width="100%">
<thead>
<tr id="tr" >
<th>Título</th>
<th>Tipo</th>
<th>Fecha</th>
<th>Área de conocimiento</th>
<th>Cupo limitado</th>
</tr>
</thead>
<tbody id="ofertaLista"></tbody>
</table>
</div>
</div>
</div>
</div>
</section>
<footer class="footer has-background-info is-mobile is-fullhd">
<div class="container">
<div class="columns is-mobil">
<div class="column is-half-fullhd">
<h1 class="title has-text-left">
Contacto
</h1>
<h2 class="subtitle has-text-left">
Direccion, correo electronico, telefono
</h2>
</div>
<div class="column is-half-fullhd">
<h2 class="subtitle has-text-right">
Powered by (c) CAEDI
</h2>
</div>
</div>
</footer>
<script src="https://www.gstatic.com/firebasejs/7.8.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.8.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.8.1/firebase-firestore.js"></script>
<script>
var firebaseConfig = {
apiKey: "AIzaSyA0Rl0WAmrpfxPZsWwc_P-AiHg44K8e05c",
authDomain: "caedi-fd241.firebaseapp.com",
databaseURL: "https://caedi-fd241.firebaseio.com",
projectId: "caedi-fd241",
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const aut = firebase.auth();
const db = firebase.firestore();
</script>
<script async type="text/javascript" src="js/bulma.js"></script>
<script src="https://unpkg.com/bulma-modal-fx/dist/js/modal-fx.min.js"></script>
<script async type="text/javascript" src="js/oferta.js"></script>
</body>
</html>
This is the final result, I want to assign different hrefs to each "Titulo" but by doing this
<td>${oferta.titulo}</td>
This happens
I want to put a href="historia.html" in "Historia del arte" and a href="matematicas.html" in "Matematicas 1", Is it possible?, sorry if I'm not expressing my self with clarity
<td>${oferta.titulo}</td>
you can do this
<td>${oferta.titulo}</td>
or
<td>${oferta.titulo}</td>
Just set the href of the element to be the variable for the URL:
<td>${oferta.titulo}</td>
Related
I'm trying to apply h2.appendChild(h2Text) to all three elements with the class name "flip-card-front". I'm trying to get h2 to display the word 'Accusation'. To make things easier i only added three cards in the html but for my project i'm trying to apply the h2 to 100 cards with the class name "flip-card-front"
window.addEventListener("DOMContentLoaded", function(){
var h2 = document.createElement("h2");
var h2Text = document.createTextNode("Accusation ");
h2.appendChild(h2Text);
console.log(h2);
document.body.appendChild(h2);
});
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<script src="app.js" ></script>
</head>
<body>
<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front">
<h2>Accusations </h2>
<img
src='https://avataaars.io/?avatarStyle=Circle&topType=LongHairStraight&accessoriesType=Blank&hairColor=BrownDark&facialHairType=Blank&clotheType=BlazerShirt&eyeType=Default&eyebrowType=Default&mouthType=Default&skinColor=Light' />
</div>
<div class="flip-card-back">
<h1>John Doe</h1>
<p>Architect & Engineer</p>
<p>We love that guy</p>
</div>
</div>
</div>
<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front">
<img
src='https://avataaars.io/?avatarStyle=Circle&topType=ShortHairTheCaesarSidePart&accessoriesType=Blank&hairColor=BrownDark&facialHairType=Blank&clotheType=BlazerShirt&eyeType=Default&eyebrowType=Default&mouthType=Default&skinColor=Light' />
</div>
<div class="flip-card-back">
<h1>John Doe</h1>
<p>Architect & Engineer</p>
<p>We love that guy</p>
</div>
</div>
</div>
<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front">
<img
src='https://avataaars.io/?avatarStyle=Circle&topType=ShortHairShortFlat&accessoriesType=Kurt&hairColor=BrownDark&facialHairType=BeardMedium&facialHairColor=BrownDark&clotheType=ShirtVNeck&clotheColor=Blue03&eyeType=Default&eyebrowType=Default&mouthType=Default&skinColor=Light' />
</div>
<div class="flip-card-back">
<h1>John Doe</h1>
<p>Architect & Engineer</p>
<p>We love that guy</p>
</div>
</div>
</div>
const front = document.getElementsByClassName("flip-card-front");
let header = document.createElement("h2");
header.innerHTML = "Accusation";
front.append(header);
ADDED:
const cards = document.getElementById("cards");
function addTitleToCards() {
for (let i = 0; i < cards.children.length; i++) {
const card = cards.children[i]
let header = document.createElement("h2")
header.innerHTML = "Accusations"
card.prepend(header)
}
}
addTitleToCards()
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Cards</title>
</head>
<body>
<div id="cards">
<div class="flip-card">
<img src='https://avataaars.io/?avatarStyle=Circle&topType=LongHairStraight&accessoriesType=Blank&hairColor=BrownDark&facialHairType=Blank&clotheType=BlazerShirt&eyeType=Default&eyebrowType=Default&mouthType=Default&skinColor=Light' />
<h3>John Doe</h3>
</div>
<div class="flip-card">
<img src='https://avataaars.io/?avatarStyle=Circle&topType=ShortHairTheCaesarSidePart&accessoriesType=Blank&hairColor=BrownDark&facialHairType=Blank&clotheType=BlazerShirt&eyeType=Default&eyebrowType=Default&mouthType=Default&skinColor=Light' />
<h3>John Doe</h3>
</div>
<div class="flip-card">
<img src='https://avataaars.io/?avatarStyle=Circle&topType=ShortHairShortFlat&accessoriesType=Kurt&hairColor=BrownDark&facialHairType=BeardMedium&facialHairColor=BrownDark&clotheType=ShirtVNeck&clotheColor=Blue03&eyeType=Default&eyebrowType=Default&mouthType=Default&skinColor=Light'
/>
<h3>John Doe</h3>
</div>
</div>
<body>
</html>
I need to copy the .container element without using innerHTML.
here the index.html
<!DOCTYPE html>
<html>
<head>
<title> </title>
<meta charset="UTF-8"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" type="text/css" href="css/test.css">
<!-- Utilitats CSS i icones Bootstrap CDN -->
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<script src="js/test.js"></script>
</head>
<body>
<div class="text-center">
<div class="card-header bg-info row">
<div class="col-sm-4">
<img src="https://pbs.twimg.com/profile_images/1046722856929947649/hytXqKH0_400x400.jpg" height="80">
</div>
<div class="col-sm-4">
<h3 class="display-4">Agenda IOC</h3>
<h4 class="text-warning">Consulta tots els esdeveniments</h4>
</div>
<div class="col-sm-4">
<h5 class="card-title">Elegeix la data:</h5>
<input id="data" type="date">
<button id="cerca">Cerca</button>
</div>
</div>
<div class="container">
<div class="card">
<div class="card_image-container">
<img class="card-image" src="http://agenda.cultura.gencat.cat/content/dam/agenda/articles/2018/07/03/033/Esculturas.jpg" alt="">
</div>
<div class="card-body">
<h3 class="card-title">Title</h3>
<p>Description</p>
Go
</div>
</div>
</div>
</div>
<!-- Utilitats js de Bootstrap CDN -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>
Copy the element and show it when click in the button.
I need to create a function that I can change the values of each element created.
I'm having struggle accomplishing this :
I want jQuery to grab class name of each icon and write it in each p element
HTML
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="container-fluid">
<div class="text-center">
<div class="row">
<div class="col-md-4">
<div class="icon"><i class="icon-class-1"></i></div>
<p></p>
</div>
<div class="col-md-4">
<div class="icon"><i class="icon-class-2"></i></div>
<p></p>
</div>
<div class="col-md-4">
<div class="icon"><i class="icon-class-3"></i></div>
<p></p>
</div>
</div>
</div>
</div>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
jQuery
function idk() {
var icon_class = $(".icon i").attr("class"),
icon_container = $(".col-md-4"),
icon_p = $('.col-md-4 p');
icon_p.each(function(){
icon_p.text(icon_class);
})
};
$(document).ready(function () {
idk();
});
JsFiddle
https://jsfiddle.net/277gpp7r/2/
This code only duplicates the first icon class name and writes it in all "p" elements instead grabbing the each class name, but this is not what I'm trying to accomplish.
I would appreciate any help, thanks in advance everyone!
I would loop through the i's, store the class in a var, then find the .col-md-4 ancestor and target the p in it and then add the class text to the p
function idk() {
$('.icon i').each(function() {
var icon_class = $(this).attr("class"),
$icon_p = $(this).closest('.col-md-4').find('p');
$icon_p.text(icon_class);
});
}
$(document).ready(function() {
idk();
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<body>
<div class="container-fluid">
<div class="text-center">
<div class="row">
<div class="col-md-4">
<div class="icon"><i class="icon-class-1"></i></div>
<p></p>
</div>
<div class="col-md-4">
<div class="icon"><i class="icon-class-2"></i></div>
<p></p>
</div>
<div class="col-md-4">
<div class="icon"><i class="icon-class-3"></i></div>
<p></p>
</div>
</div>
</div>
</div>
</body>
function idk() {
var icon_class = $(".icon i").map(function(){
return $(this).attr("class")
}).get().join( " " )
icon_container = $(".col-md-4"),
icon_p = $('.col-md-4 p');
icon_p.each(function() {
icon_p.text(icon_class);
})
};
$(document).ready(function() {
idk();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-fluid">
<div class="text-center">
<div class="row">
<div class="col-md-4">
<div class="icon"><i class="icon-class-1"></i></div>
<p>1</p>
</div>
<div class="col-md-4">
<div class="icon"><i class="icon-class-2"></i></div>
<p>2</p>
</div>
<div class="col-md-4">
<div class="icon"><i class="icon-class-3"></i></div>
<p>3</p>
</div>
</div>
</div>
</div>
Map all the class into one array.
Then use that array as the text of each p
Try some thing like this.
function idk() {
$('.col-md-4').each(function(){
var icon_class = $(this).find(".icon i").attr("class");
console.log(icon_class);
icon_container = $(".col-md-4");
icon_p = $(this).find('p');
icon_p.text(icon_class);
});
};
$(document).ready(function () {
idk();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="container-fluid">
<div class="text-center">
<div class="row">
<div class="col-md-4">
<div class="icon"><i class="icon-class-1"></i></div>
<p></p>
</div>
<div class="col-md-4">
<div class="icon"><i class="icon-class-2"></i></div>
<p></p>
</div>
<div class="col-md-4">
<div class="icon"><i class="icon-class-3"></i></div>
<p></p>
</div>
</div>
</div>
</div>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
You can do like this
function idk() {
var icon_p = $('.col-md-4 p');
icon_p.each(function(i, v) {
find the i & its class in previous div and add it t the element
var findClass = $(this).prev('div.icon').find('i').attr('class');
$(this).attr('class', findClass);
})
};
DEMO
text(function) is shortest way to do this:
$('.col-md-4 p').text(function(){
return $(this).prev().find('i').attr('class')
})
p{border:1px solid #ccc; margin-top:10px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-fluid">
<div class="text-center">
<div class="row">
<div class="col-md-4">
<div class="icon"><i class="icon-class-1"></i></div>
<p></p>
</div>
<div class="col-md-4">
<div class="icon"><i class="icon-class-2"></i></div>
<p></p>
</div>
<div class="col-md-4">
<div class="icon"><i class="icon-class-3"></i></div>
<p></p>
</div>
</div>
</div>
</div>
So i am trying to export a specific div to a PDF file and i am failing miserably...
This is the page:
<!DOCTYPE HTML>
<html>
<head>
<title>Testpage</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<!--[if lte IE 8]><script src="../assets/js/ie/html5shiv.js"></script><![endif]-->
<link rel="stylesheet" href="../assets/css/jquery.dataTable.min.css" />
<link rel="stylesheet" href="../assets/css/main.css" />
<link rel="stylesheet" href="../assets/css/toastr.css" />
<link rel="stylesheet" href="../assets/css/chart.css" />
<!--[if lte IE 9]><link rel="stylesheet" href="../assets/css/ie9.css" /><![endif]-->
<!--[if lte IE 8]><link rel="stylesheet" href="../assets/css/ie8.css" /><![endif]-->
</head>
<body>
<!-- Wrapper -->
<div id="wrapper">
<!-- Main -->
<div id="main">
<div class="inner" id="inner">
<!-- Header -->
<header id="header">
<h2><strong>Test</strong></h2>
</header>
<!-- Content -->
<section>
<!-- Table -->
<h3>Table</h3>
<div class="table-wrapper">
<table id="myTable">
<thead>
<tr>
<th>Time</th>
<th>Speed</th>
<th>Meters</th>
</tr>
</thead>
<tbody>
<?php
require_once ('showData.php');
?>
</section>
</div>
</div>
<!-- Sidebar -->
<div id="sidebar">
<div class="inner">
<!-- Menü -->
<nav id="menu">
<header class="major">
<h2>Menü</h2>
</header>
<ul>
<li>Home</li>
<li>
<span class="opener">Test</span>
<ul>
<li>Test1</li>
<li>Test2</li>
</ul>
</li>
</ul>
</nav>
<!-- Filter -->
<section>
<header class="major">
<h2>Filter</h2>
</header>
<form method="post" id="submitdata" name="submitdata">
<div class="row uniform">
<div class="12u 12u$">
<input type="text" name="datefrom" id="datefrom" value="" placeholder="Date from" />
</div>
<div class="12u 12u$">
<input type="text" name="dateto" id="dateto" value="" placeholder="Date to" />
</div>
<div class="12u$">
<div class="select-wrapper">
<select name="dropdown" id="dropdown">
<option value="0">- Choose -</option>
<option value="1">All</option>
<option value="2">Speed</option>
<option value="3">Meter</option>
</select>
</div>
</div>
<div class="12u$">
<ul class="actions">
<li><input type="submit" id="btnSubmit" value="Clickme" class="special" /></li>
<li><input type="reset" value="Reset" /></li>
</ul>
</div>
</div>
</form>
</section>
<!-- Exportmenü -->
<section>
<header class="major">
<h2>Export</h2>
</header>
<div class="12u 12u$">
<button id="btnExport" class="button special icon fa-file-pdf-o">Export as PDF</button>
</div>
</section>
<!-- Footer -->
<footer id="footer">
<p> Stuff </p>
</footer>
</div>
</div>
</div>
<!-- Scripts -->
<script src="../assets/js/jquery.min.js"></script>
<script src="../assets/js/skel.min.js"></script>
<script src="../assets/js/util.js"></script>
<script src="../assets/js/jquery.dataTables.min.js"></script>
<!--[if lte IE 8]><script src="../assets/js/ie/respond.min.js"></script><![endif]-->
<script src="../assets/js/main.js"></script>
<script src="../assets/js/toastr.js"></script>
<script src="../assets/js/submitData.js"></script>
<script>
$(document).ready(function() {
$('#myTable').DataTable( {
"pagingType": "full_numbers"
});
});
</script>
</body>
</html>
I am trying to get everything in <div class="inner" id="inner"> into an PDF-File but nothing seems to work. I tried with jsPDF and html2canvas (html -> img -> pdf) but the quality is VERY bad. Nothing else seems to work.
I would appreciate some pointers like what i can use to get it working.
Thank you very much,
Skar
EDIT:
This is what i included after the jsPDF recommendation
<script src="../assets/jsPDF/jspdf.debug.js"></script>
<script src="../assets/jsPDF/examples/js/html2canvas.js"></script>
<script>
var doc = new jsPDF();
var specialElementHandlers = {
'#header': function(element, renderer){
return true;
}
};
$('#btnExport').click(function(){
var html=$("#inner").html();
doc.fromHTML(html,0,0, {
'width': 500,
'elementHandlers': specialElementHandlers
});
doc.save("Test.pdf");
});
</script>
Try this library, it is built for client side PDF generation.
https://parall.ax/products/jspdf
Here is the github link
I have 2 html page and one app.js
my search-movie.html code as the following :
<!DOCTYPE html>
<html ng-app="adphorusWork">
<head lang="en">
<meta charset="UTF-8">
<title>Search Movie</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="scripts/angular.min.js"></script>
<script src="scripts/angular-route.min.js"></script>
<script src="scripts/jquery-1.9.1.min.js"></script>
<script src="app/app.js"></script>
</head>
<body ng-controller="searchMovieController">
<div class="navbar navbar-default navbar-fixed-top" style="margin-top: 20px;">
<div class="container-fluid">
<ul>
<li>
OMDb Api
</li>
</ul>
</div>
</div>
<div class="container" style="margin-top: 50px;">
<div class="bs-docs-section" id="">
<div class="row">
<div class="col-lg-12">
<div class="page-header">
<h2>My Github</h2>
</div>
<div class="bs-component">
<form class="well form-search" id="search-movie" onsubmit="return false;">
<fieldset>
<legend>Search Movie</legend>
</fieldset>
<div>
<label class="control-label" for="movie-name">Movie Name : </label>
<input type="text" id="movie-name" class="input-small" style="margin-left: 10px;">
<button id="btn-search-movie" type="button" class="btn-sm btn-primary" style="margin-left: 10px;" ng-click="searchMovie()">
<span class="glyphicon glyphicon-search"> Search</span>
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
and my result-movie.html code as the following :
<!DOCTYPE html>
<html>
<head ng-app="adphorusWork">
<meta charset="UTF-8">
<title>Search Movie</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="scripts/angular.min.js"></script>
<script src="scripts/angular-route.min.js"></script>
<script src="app/app.js"></script>
<script src="scripts/jquery-1.9.1.min.js"></script>
</head>
<body ng-controller="resultMovieController">
<div class="navbar navbar-default navbar-fixed-top" style="margin-top: 20px;">
<div class="container-fluid">
<ul>
<li>
OMDb Api
</li>
</ul>
</div>
</div>
<div class="container" style="margin-top: 50px;">
<div class="bs-docs-section" id="">
<div class="row">
<div class="col-lg-12">
<div class="page-header">
<h2>My Github</h2>
</div>
<div class="bs-component">
<fieldset>
<legend>Result for Search Movie</legend>
</fieldset>
<div>
<button id="btn-result-movie" type="button" class="btn-sm btn-primary" style="margin-top: 40px;" ng-click="backtohome()">
<span class="glyphicon glyphicon-circle-arrow-left"> Home</span>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
and my app.js as the following :
(function (angular) {
'use strict';
var app = angular.module('adphorusWork', []);
app.controller('searchMovieController', function ($scope) {
$scope.searchMovie = function () {
alert("come")
}
});
app.controller('resultMovieController', function ($scope) {
$scope.backtohome = function () {
alert("home")
}
});
})(angular);
My search button is working (in search-movie.html) but my 'Home' button not working(in result-movie.html)
I'm using the same ng-app in two html page. I want to work on other button(so Home button)
Where am I doing wrong ? or How can I fix this error ?
you need to use Angular Ui router for this. And #Lex is correct you are not following the angular SPA framewrok.
This is a good read :https://github.com/angular-ui/ui-router
this link can provide a brief detail about angular ui router https://scotch.io/tutorials/angular-routing-using-ui-router
You don't have:
<script src="app/app.js"></script>
in your result-movie.html page. The bigger question, though, is why are you structuring it like this? Angular is designed as a single page application (SPA) framework. The way you are buidling it I think you are going to end up with a lot of issues long term.
I have noticed that you not include in result-movie.html page
<script src="app/app.js"></script>
as for best approach is you can use ngRoutefor data passing between controllers