I cannot figure out why the compare function I have and the insert function I have are not working. I believe one part of it might be because the function is never being called by the button? How exactly can I tell that? It does not seem like alerts are working in angular code.
this is my loginHandler.js
(function() {
var app = angular.module('loginHandler', []);
app.controller('LoginController', ['$http' ,function($http){
var database = this;
this.validated = false;
database.dbData = [];
$http.get('/resources/DatabaseObject.json').success(function(data){
database.dbData = data;
});
this.login = function(credentials){
loggedInUser = credentals.username;
validated = true;
$http.get('/resources/DatabaseObject.json').success(function(data){
$scope.dbData.push({"123":{"username":"meph","ip":"123","timeLastLogin":"123"}}, "session");
});
};
this.checkSession = function(){
var ip = "123456";
if(session.ip.equals(123456)){
return true;
}
};
}]);
})();
Neither of the functions are working.... Not the login or the checkSession.
DatabaseObject.json
[{
"users": {
"cra": {
"firstName": "Jn",
"lastName": "it",
"username": "dmph",
"email": "ran61#yahoo.com",
"ip": "192.168.1.1",
"password": "1234",
"computerName": "os",
"prviateKey": "1D3RW12390ASLEWRQ1235"
},
"mus": {
"firstName": "James",
"lastName": "mh",
"username": "ch",
"email": "j61#gmail.com",
"ip": "192.168.1.1",
"password": "11212",
"computerName": "ops",
"prviateKey": "1D3RW12390ASLEWRQ1235"
}
},
"session": {
"123456": {
"username": "crh",
"ip": "123456",
"timeLastLogin": "123456787654"
}
}
}]
and here is my html
<html lang="en" ng-app="gemStore">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<title>Basic Company Template for Bootstrap 3</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.css" rel="stylesheet">
<!-- Custom CSS for the 'One Page Wonder' Template -->
<link href="css/one-page-wonder.css" rel="stylesheet">
<script type="text/javascript" src="angular/angular.min.js"></script>
<script type="text/javascript" src="script/headerPanel.js"></script>
<script type="text/javascript" src="script/errorHandler.js"></script>
<script type="text/javascript" src="script/loginHandler.js"></script>
<script type="text/javascript" src="script/sessionHandler.js"></script>
</head>
<body ng-controller="NameController as name">
<div ng-controller="ErrorController as errorController">
<div ng-controller="LoginController as loginCtrl">
<nav class="navbar navbar-fixed-top navbar-inverse" role="navigation">
<div class="container" ng-controller="CredentialsController as credentials">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">Home</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li><a class="act" href="#about">About</a>
</li>
<li>Services
</li>
<li>Tutorial
</li>
<li>Features
</li>
<li>Download
</li>
</ul>
<form>
<ul class="nas navbar-na">
<li ng-hide="loginCtrl.checkSession(loginCtrl.dbData.session)"><a>User ID: <input ng-model="credentials.username" type="text"></a></li>
<li ng-hide="loginCtrl.checkSession(loginCtrl.dbData.session)"><a>Password: <input ng-model="credentials.password" type="password" onkeyup="if (event.keyCode == 13) document.getElementById('loginBtn').click()"></a></li>
<li style="color: red;" ng-show="loginCtrl.checkSession(loginCtrl.dbData.session)"><h2>LOGGED IN AS {{credentials.username}}</h2></li>
</ul>
<ul class="nav navbar-nav">
<li><a ng-click="loginCtrl.login(credentials)" method="post" novalidate type="submit" href="index.html" id="loginBtn">Login</a></li>
</ul>
</form>
</div>
<!-- /.navbar-collapse -->
</div>
<div style="color: red;" ng-repeat="login in loginCtrl.dbData">
<h1>{{login.session}}</h1>
</div>
</nav>
</div>
<div style="color: red;" ng-repeat="errorArray in errorController.errors">
<h1>{{errorArray.error}}</h1>
</div>
</div>
<div class="header-image">
<div class="headline">
<div class="container">
<h1>{{name.name}}</h1>
<h2>The Impossible!</h2>
</div>
</div>
</div>
</body>
</html>
I am not sure if that submit button is ok or not.... Bah! Sorry.... Im really bad at this stuff! I hope someone can help me better understand it, I have been trying different things without anything working.
http://plnkr.co/edit/zYSFmQSU83FMC9UcXhM4?p=preview
The push doesn't work, because you have database.dbData, but trying to push into $scope.dbData (which doesn't exist).
The comparing doesn't work, because you compare against session.ip (which isn't defined anywhere).
I believe it's because you are using this. instead of $scope.
Also, you aren't passing $scope to your parameters...
app.controller('LoginController', ['$http' ,function($http){
It should be:
app.controller('LoginController', ['$http, $scope' ,function($http, $scope){
And down below you should be using: (not this)
$scope.login = function () { /* ... */ };
$scope.checkSession = function () { /* ... */ };
Related
This is my first time asking or doing this type of question
So I created this page http://lamp.cse.fau.edu/~mcuervo5/p4/
and it does your basic to do app list thing for adding and deleting stuff.
Apparently the only thing missing is to save the data on the current page. I heard that there a code that can save the current page to a local storage that has everything already in it, so when I re-open the link, instead of having nothing in the "complete and incomplete" list, it should look like this
thanks, it the only part I have left to do & I dont know if it implemented in HTMl or Jquery. I do not know how to do it.
and if you want to see the code here instead of "inspect" from the page with the link above, here it is. for html and Jquery
$(document).ready(function() {
// $('#list').innerhtml = localStorage.getItem("List");
//$('#incomplete-tasks').html("<P>I just replaced your stuff.</P>");
$("#Sumbit_Button").click(function() {
var textbox_Value = $("#textbox").val();
$('#incomplete-tasks').append('<li><span class="text" contenteditable="false">' + textbox_Value + "</span>" +
'<input/ style="display: none" class="new-value">' +
"<button type='button' class='delete'>Delete</button>" +
"<button type='button' class='edit'>Edit</button></li>");
});
$('#incomplete-tasks').on('click', '.delete', function() {
console.log('i am clicked.delete');
$(this).parent().remove();
});
$('#incomplete-tasks').on('click', '.edit', function() {
console.log("complete task click.edit");
$(this).siblings('input').show();
$(this).siblings('.delete').hide();
$(this).hide();
});
$('#incomplete-tasks').on('click', '.edit', function() {
console.log("INcomplete task click.edit");
$(this).siblings('input').show();
$(this).siblings('span').hide();
$(this).siblings('.delete').hide();
$(this).hide();
});
$('#incomplete-tasks').on('keyup', '.new-value', function(e) {
if (e.keyCode == 13) {
console.log("Complete Task _Version 2.new_value");
$(this).siblings('span').text($(this).val()).show();
$(this).siblings('input').hide();
$(this).siblings('.delete').show();
$(this).siblings('.edit').show();
$(this).hide();
}
});
$('#incomplete-tasks').on('click', '.text', function() {
var li = $(this).parent().remove().toggleClass("strikethrough");
$('#complete-tasks').append(li);
});
$('#complete-tasks').on('click', '.delete', function() {
console.log('i am clicked.delete');
$(this).parent().remove();
});
$('#complete-tasks').on('click', '.edit', function() {
console.log("complete task click.edit");
$(this).siblings('input').show();
$(this).siblings('.delete').hide();
$(this).hide();
});
$('#complete-tasks').on('click', '.edit', function() {
console.log("INcomplete task click.edit");
$(this).siblings('input').show();
$(this).siblings('span').hide();
$(this).siblings('.delete').hide();
$(this).hide();
});
$('#complete-tasks').on('keyup', '.new-value', function(e) {
if (e.keyCode == 13) {
console.log("Complete Task _Version 2.new_value");
$(this).siblings('span').text($(this).val()).show();
$(this).siblings('input').hide();
$(this).siblings('.delete').show();
$(this).siblings('.edit').show();
$(this).hide();
}
});
$('#complete-tasks').on('click', '.text', function() {
var li = $(this).parent().remove().toggleClass("strikethrough");
$('#incomplete-tasks').append(li);
});
// var save()
//{
// localStorage.setItem("List", $("#list").innerhtml());
// }
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>The Reminder list</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<script src="http://cdn.jsdelivr.net/jquery.validation/1.14.0/jquery.validate.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" />
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<!-- Custom CSS -->
<link href="css/heroic-features.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">To Do List</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>
About
</li>
<li>
Services
</li>
<li>
Contact
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Page Content -->
<div class="container">
<!-- Jumbotron Header -->
<header class="jumbotron hero-spacer">
<h1> The Reminder Friend App </h1>
<p>this is my to do list app. type in the list you want to add & store in the list
</p>
<form>
<!-- textbox -->
<input type="text" id="textbox">
<!--add button -->
<input type="button" id="Sumbit_Button" value="Add">
</form>
</header>
<hr>
<div id='lists'>
<!-- Page Features -->
<div class="row text-center">
<div class="col-md-6 col-sm-6 hero-feature">
<div class="thumbnail">
<div class="caption">
<h3>Incomplete</h3>
<ul id="incomplete-tasks">
</ul>
</div>
</div>
</div>
<div class="col-md-6 col-sm-6 hero-feature">
<div class="thumbnail">
<div class="caption">
<h3>Complete</h3>
<ul id="complete-tasks">
</ul>
</div>
</div>
</div>
</div>
</div>
<!-- /.row -->
<hr>
<!-- Footer -->
<footer>
<div class="row">
<div class="col-lg-12">
<p>Copyright © Mauricio Cuervo 2017</p>
</div>
</div>
</footer>
</div>
<!-- /.container -->
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
</body>
<script src="p4.js"></script>
</html>
Hello you can do something like this:
$("#Sumbit_Button").click(function() {
var textbox_Value = $("#textbox").val();
var list = [];
list.push(textbox_Value);
localStorage.setItem("listdata", list);
// do not manage using `append` whole html. Manage through list and display as you want
});
on page load call:
var stored = localStorage.getItem("listdata");
Now here you can manage array of items and iterate on complete & incomplete list.
So whenever any action of edit, delete, add occurs you have to just manage the localstorage instance on each call. and based on that just iterate list whereever you want.
I have an angular route defined for the bootstrap main menu items. I have another view (HTML page) that implements isteven multiselection directives. As I understand it (newbie with angular and bootstrap), controllers are activated when routes change.
How can I cause the child view controller to be executed from the parent controller?
EDIT
MAIN HTML
<!DOCTYPE html>
<html lang="en" data-ng-app="wtApp">
<head>
<meta charset="utf-8" />
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<title>Writer's Tryst, where authors and publishers, producers, agents meet.</title>
<meta name="description" content="A better way for writers to find publishers, producers and agents" />
<link href='https://fonts.googleapis.com/css?family=Lobster+Two:700italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Ubuntu:400,500' rel='stylesheet' type='text/css'>
<link href='css/main.css' rel='stylesheet' type='text/css' />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="frainversegment" content="!" />
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.0/css/font-awesome.css" />
<link rel="stylesheet" href="http://getbootstrap.com/dist/css/bootstrap.css" />
<link rel="stylesheet" href="css/main.css" />
<link rel="stylesheet" href="css/shares.css" />
<link rel="shortcut icon" href="img/icons/writers-tryst.png" />
<!--
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-15499108-1");
pageTracker._trackPageview();
} catch (err) { }
</script>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-3982825388677642",
enable_page_level_ads: true
});
</script>
-->
</head>
<body>
<header>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#Writers-Tryst">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><img id="logo" src="img/writers-tryst-logo.png" alt="logo" /></a>
</div>
<div class="collapse navbar-collapse" id="Writers-Tryst">
<ul class="nav navbar-nav">
<li class="active"><a id="homepage" href="#"><i class="glyphicon glyphicon-home"></i> Home</a></li>
<li> Writers</li>
<li> Enablers</li>
<li> About</li>
<li> Privacy/Rules</li>
<li> Contact</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><i class="glyphicon glyphicon glyphicon-log-in"></i> Log-In</li>
<li><a id="create-account-link" href="#accounts"><i class="glyphicon glyphicon-user"></i> Create Account</a></li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li><a id="update-profile" href="#update-profile">Update profile</a></li>
<li><a id="manage-uploads" href="#manage-uploads">Manage uploads</a></li>
</ul>
</li>
<li ><a id="reset-pwd-link" href="#reset-pwd"></a></li>
</ul>
</div>
</div>
</nav>
<!--
<div class="google-ad-top">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-3982825388677642"
data-ad-slot="1133448516"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
-->
</header>
<div id="shares">
<!-- Twitter -->
<a href="http://twitter.com/share?url=writers.tryst.ron-tornambe.com&text=<TEXT>&via=<VIA>" target="_blank" title="twitter" class="share-btn twitter">
<i class="fa fa-twitter"></i>
</a>
<!-- Google Plus -->
<a href="https://plus.google.com/share?url=writers.tryst.ron-tornambe.com" target="_blank" title="google+" class="share-btn google-plus">
<i class="fa fa-google-plus"></i>
</a>
<!-- Facebook -->
<a href="http://www.facebook.com/sharer/sharer.php?u=writers.tryst.ron-tornambe.com" target="_blank" title="facebook" class="share-btn facebook">
<i class="fa fa-facebook"></i>
</a>
<!-- StumbleUpon (url, title) -->
<a href="http://www.stumbleupon.com/submit?url=writers.tryst.ron-tornambe.com&title=<TITLE>" target="_blank" class="share-btn stumbleupon">
<i class="fa fa-stumbleupon"></i>
</a>
<!-- Reddit (url, title) -->
<a href="http://reddit.com/submit?url=writers.tryst.ron-tornambe.com&title=<TITLE>" target="_blank" class="share-btn reddit">
<i class="fa fa-reddit"></i>
</a>
<!-- LinkedIn -->
<a href="http://www.linkedin.com/shareArticle?url=writers.tryst.ron-tornambe.com&title=<TITLE>&summary=<SUMMARY>&source=<SOURCE_URL>" target="_blank" title="linked-in" class="share-btn linkedin">
<i class="fa fa-linkedin"></i>
</a>
</div>
<div>
<p id="message"></p>
<div id="main" class="content">
<!-- angular templating -->
<!-- this is where content will be injected -->
<div data-ng-view></div>
</div>
</div>
<footer>
<div id="copyright">© 2016, Ronald Tornambe, Inc.</div>
</footer>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="js/common.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="js/pages.js"></script>
<script type="text/javascript" async src="//platform.twitter.com/widgets.js"></script>
<script>
$("#drop-toggle-1").on("click", function (e) {
e.preventDefault();
});
$("#update-profile").on("click", function () {
sessionStorage.setItem("create-or-update", "update");
console.log("session-storage=" + sessionStorage.getItem("create-or-update"))
$("#create-account-link").trigger("click");
});
</script>
</body>
</html>
** MAIN CONTROLLER - JS**
var wtApp = angular.module('wtApp', ['ngRoute'])
wtApp.config(function ($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl: 'pages/home.html',
controller: 'mainController'
})
// route for the writers page
.when('/writers', {
templateUrl: 'pages/writers.html',
controller: 'writersController'
})
// route for the enablers page
.when('/enablers', {
templateUrl: 'isteven.html.html',
controller: 'enablersController'
})
// route for privacy/rues
.when('/privacy', {
templateUrl: 'pages/privacy.html'
})
// route for the about page
.when('/about', {
templateUrl: 'pages/about.html',
controller: 'aboutController'
})
// route for the contact pagefa
.when('/contact', {
templateUrl: 'pages/contact.html',
controller: 'contactController'
})
// route for the log-in page
.when('/log-in', {
templateUrl: 'pages/login.html',
controller: 'loginController'
})
// route for the create account
.when('/accounts', {
templateUrl: 'pages/accounts.html',
controller: 'createAccountController'
})
// route for manage uploads
.when('/manage-uploads', {
templateUrl: 'pages/manage-uploads.html'
})
});
// create the controller and inject Angular's $scope
wtApp.controller('mainController', function($scope) {
$scope.example2model = []; $scope.example2data = [ {id: 1, label: "David"}, {id: 2, label: "Jhon"}, {id: 3, label: "Danny"}]; $scope.example2settings = {displayProp: 'id'};
resetNavbar();
$("a[href$='']").css({color:'#FF5733'});
});
wtApp.controller('writersController', function($scope) {
resetNavbar();
$("a[href$='writers']").css({color:'#FF5733'});
});
wtApp.controller('enablersController', function($scope) {
$scope.worktype = [
{ icon: "<img src=img/icons/smile-mask.png />", name: "Fiction", ticked: false },
{ icon: "<img src=img/icons/frown-mask.png />", name: "Non-Fiction", ticked: false }
];
resetNavbar();
$("a[href$='enablers']").css({color:'#FF5733'});
});
wtApp.controller('aboutController', function($scope) {
resetNavbar();
$("a[href$='about']").css({color:'#FF5733'});
});
wtApp.controller('contactController', function($scope) {
resetNavbar();
$("a[href$='contact']").css({color:'#FF5733'});
});
wtApp.controller('loginController', function ($scope) {
resetNavbar();
$("a[href$='log-in']").css({ color: '#FF5733' });
});
wtApp.controller('createAccountController', function ($scope) {
resetNavbar();
$("a[href$='create-account']").css({ color: '#FF5733' });
});
wtApp.controller('ResetPasswordController', function ($scope) {
// $("a[href$='reset-pwd']").css({ color: '#FF5733' });
});
function resetNavbar() {
$(".navbar-collapse a").not("a[href='#']").each(function () {
$(this).css({ 'color': 'black' })
});
}
CHILD HTML AND JS
<html data-ng-app="myApp" id="myApp" lang="en">
<head>
<title>Writer's Tryst - Enablers Form</title>
<link type="text/css" href="css/enablers.css" rel="stylesheet" />
<link rel="stylesheet" href="css/isteven-multi-select.css">
</head>
<body data-ng-controller="MainCtrl">
<div class="container center_div">
<img id="img-enablers" src="#" alt="images" />
<form id = "form-enablers" class="form-horizontal well">
<h1>Enablers</h1>
<label for="work-type" class="fixed50">Type:</label>
<p id="work-type"
data-isteven-multi-select
data-input-model="worktype"
data-output-model="outputWorktype"
data-button-label="icon name"
data-item-label="icon name"
data-tick-property="ticked"
></p>
<label for="form-type" class="fixed50">Form:</label>
<p id="form-type"
data-isteven-multi-select
data-input-model="formtype"
data-output-model="outputFormtype"
data-button-label="name"
data-item-label="name"
data-tick-property="ticked"
></p>
<p>For an explanation of the genres shown here, see <a target="_blank" href="https://en.wikipedia.org/wiki/List_of_genres">List of genres</a><br/></p>
<label for="genres" class="fixed50">Genres:</label>
<p id="genres"
data-isteven-multi-select
data-input-model="genres"
data-output-model="outputGenres"
data-button-label="name"
data-item-label="name"
data-tick-property="ticked"
></p>
<label for="accepted-media" class="fixed50">Accepted Media:</label>
<p id="accepted-media"
data-isteven-multi-select
data-input-model="acceptedMedia"
data-output-model="outputMedia"
data-button-label="icon name"
data-item-label="icon name"
data-tick-property="ticked"
></p>
<p> <label for="special-instructions" class="fixed50">Special Instructions</label>
<textarea id ="special-instructions" name="special-instructions"></textarea>
</p>
<p>For a limited time, enablers can use this site for <span style="color: #f00; font-weight:bold">FREE</span>. We reserve the right to change this policy without notice.</p>
<div id="recaptcha-elements"></div>
<div class="form-group">
<button type="submit" id="enablers-search" class="btn btn-default glyphicon glyphicon-search"> Search</button>
</div>
<input id="userid" name="userid" type="hidden" />
</form>
</div>
<form id="writers-list">
<p>To request a manuscript, click the checkbox beneath the thumbs-up icon.</p>
<div id="table-list"></div>
<div id="main" class="content"></div>
</form>
<script src="js/isteven-multi-select.js"></script>
<script src="js/enablers.js"></script>
<script src="js/recaptcha.js"></script>
<script>
var myApp = angular.module("myApp", ["isteven-multi-select"]);
myApp.controller('MainCtrl', function ($scope) {
$scope.worktype = [
{ icon: "<img src=img/icons/smile-mask.png />", name: "Fiction", ticked: false },
{ icon: "<img src=img/icons/frown-mask.png />", name: "Non-Fiction", ticked: false }
];
$scope.formtype = [];
var data = {};
data.action = 'multiselect-forms';
ajax('post', 'php/enablers.php', data, formsSuccess, 'Error retrieving multiselect forms data: ');
function formsSuccess(data) {
console.log(data);
$scope.formtype = eval(data);
}
$scope.genres = [];
data.action = 'multiselect-genres';
ajax('post', 'php/enablers.php', data, genresSuccess, 'Error retrieving multiselect forms data: ');
function genresSuccess(data) {
console.log(data);
$scope.genres = eval(data);
}
$scope.acceptedMedia = [
{ icon: "<img src=img/home/mail.png />", name: "Mail", ticked: false },
{ icon: "<img src=img/icons/pdf.png />", name: "PDF File", ticked: false }
];
});
</script>
</body>
</html>
Unfortunatelly you can't. Only inner scopes can execute what is given from their parents.
What you may do is give the inner scope as a parameter for the outer one, it is:
Create A, the parent scope.
The parent A, should bootstrap B and put it instance in a variable, like A.contollerB
Associate the created instance, A.controllerB to the tag scope you need.
Please, say me if it's not enought to help you.
Edit: Code example
Anywhere in main controller initialization, you should pass it`s reference to a variable in $scope:
myApp.controller('MainCtrl', function ($scope) {
this.writersController = $controller('writersController',{$scope: $scope});
In the route, reference the variable for wirterController inside the controller you made.
I have an MVC app that uses the _Layout page to render a header and a sidebar in every page. I am trying to use Angular's Accordion for the menus. However, as soon as I try to place a controller in my _Layout page all of my angular code stops working (I have angular in the Index.cshtml which displays via RenderBody()).
Here is my _Layout page code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>#ViewBag.Title</title>
#Styles.Render("~/Content/css")
#Scripts.Render("~/bundles/modernizr")
#Scripts.Render("~/bundles/jquery")
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/angular-sanitize.js"></script>
<script src="~/Scripts/ui-bootstrap-custom-tpls-0.13.3.js"></script>
<link href="~/Content/Layout.css" rel="stylesheet" />
<script src="~/Scripts/app/app.js"></script>
<script src="~/Scripts/app/LayoutCtrl.js"></script>
<script src="~/Scripts/app/generalsearchService.js"></script>
</head>
<body>
<header>
<div class="content-wrapper">
<div class="float-left">
<p class="site-title">
</div>
<div class="float-right">
<nav>
</nav>
</div>
</div>
</header>
<div ng-app="myModule" ng-controller="LayoutCtrl">
<nav class='sidebar sidebar-menu-collapsed'>
<a href='#' id='justify-icon'>
<span class='glyphicon glyphicon-triangle-right'>
</span>
</a>
<ul>
<li class='active'>
<a class='expandable' href='#' title='Dashboard'>
<div id="myTab" class='vertical-text collapsed-element' style="color:blue; width:300px">Expand For Menu Options
</div>
<span class='expanded-element'>Dashboard</span>
</a>
</li>
<li>
<a class='expandable' href='#' title='APIs'>
<span class="collapsed-element"></span>
<span class='expanded-element'>APIs</span>
</a>
</li>
<li>
<a class='expandable' href='#' title='Settings'>
<span class="collapsed-element"></span>
<span class='expanded-element'>Settings</span>
</a>
</li>
<li>
<a class='expandable' href='#' title='Account'>
<span class="collapsed-element"></span>
<span class='expanded-element'>Account</span>
</a>
</li>
</ul>
<a href='#' id='logout-icon' title='Logout'>
<span class="collapsed-element"></span>
<span class='glyphicon glyphicon-off'></span>
</a>
</nav>
<nav>
<accordion close-others="oneAtATime">
<accordion-group is-open="status.open">
<accordion-heading>
</accordion-heading>
</accordion-group>
</accordion>
</nav>
</div>
<div id="myBody" style="margin-top:50px; margin-left:320px; width:80%; position:absolute">
#RenderBody()
</div>
#Scripts.Render("~/bundles/jquery")
#RenderSection("scripts", required: false)
<script type="text/javascript">
(function () {
$(function () {
var collapseMyMenu, expandMyMenu, toggleGlyphCollapse, toggleGlyphExpand, hideMenuTexts, showMenuTexts;
expandMyMenu = function () {
document.getElementById('myBody').style.width = '80%';
document.getElementById('myBody').style.marginLeft = '320px';
document.getElementById('myTab').style.color = '#E6E7E8';
return $("nav.sidebar").removeClass("sidebar-menu-collapsed").addClass("sidebar-menu-expanded");
};
collapseMyMenu = function () {
document.getElementById('myBody').style.width = '99%';
document.getElementById('myBody').style.marginLeft = '70px';
document.getElementById('myTab').style.color = 'blue';
return $("nav.sidebar").removeClass("sidebar-menu-expanded").addClass("sidebar-menu-collapsed");
};
showMenuTexts = function () {
return $("nav.sidebar ul a span.expanded-element").show();
};
hideMenuTexts = function () {
return $("nav.sidebar ul a span.expanded-element").hide();
};
return $("#justify-icon").click(function (e) {
if ($(this).parent("nav.sidebar").hasClass("sidebar-menu-collapsed")) {
expandMyMenu();
showMenuTexts();
$(this).css({
color: "#000"
});
} else if ($(this).parent("nav.sidebar").hasClass("sidebar-menu-expanded")) {
collapseMyMenu();
hideMenuTexts();
$(this).css({
color: "#FFF"
});
}
$(this).find('span').toggleClass('glyphicon-triangle-right').toggleClass('glyphicon-triangle-left');
return false;
});
});
}).call(this);
</script>
</body>
</html>
here is my Angular controller for the _Layout:
angular.module('myModule').controller('LayoutCtrl', function ($scope, generalsearchService) {
getmenuItems();
function getmenuItems() {
generalsearchService.GetMenuItems()
.success(function (data) {
$scope.menuItems = data;
});
};
});
The Angular in my Index.cshtml page works fine until I add the above to the _Layout page.
Can anyone tell me what I am missing? I've been working on this for hours and just can't seem to figure it out.
Any assistance is greatly appreciated!
I found a workaround for my issue, although it is not the best solution because it will require that I put everything in one controller. The workaround is to put a div around everything in the body of my _Layout page(which includes the "#RenderBody" which renders my Index page) and include the ng-app and ng-controller in that div on the _Layout page. If anyone knows of a better solution..I'm all ears. Thanks to those who took the time to try to help thus far.
I'm trying to implement some notification on y cordova based project using AngularJS as FO.
What i did :
0/ register an id on GCM
1/ installed the plugin https://github.com/phonegap-build/PushPlugin.git
2/ included last version of cordova.js in my index.html
code :
<html ng-app="baclyApp">
<head>
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/angular-growl.min.css">
<title>Bacly Mobile</title>
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top" role="navigation" id='nav1' ng-controller="navCtrl">
<div class="container-fluid">
<div class="">
<ul class="nav navbar-nav navbar-left">
<li>
<a class="navbar-brand" ui-sref="home">
Bacly Mobile
</a>
</li>
</ul>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li><a ng-click="init1()"><span class="glyphicon glyphicon-refresh"></span></a></li>
<li><a ui-sref="login"><span class="glyphicon glyphicon-user"></span></a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div>
</div>
<div class="navbar navbar-default navbar-static-top">
<div class='container'>
<ul class="nav nav-justified">
<li><a ui-sref="home"><span class="glyphicon glyphicon-home"></span></a></li>
<li><a ui-sref="tournois"><span class="glyphicon glyphicon-calendar"></span></a></li>
<li><a ui-sref="defi"><span class="glyphicon glyphicon-sort"></span></a></li>
<li><a ui-sref="pointage"><span class="glyphicon glyphicon-pencil"></span></a></li>
</ul>
</div>
</div>
<div class='container-fluid' id="maincontainer">
<div class"col-xs-12 col-sd-12 col-md-12 col-ld-12 container" ui-view="main">
</div>
</div>
<div growl></div>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
<script src="js/angular.js"></script>
<script src="js/underscore.js"></script>
<script src="js/angular-ui-bootstrap-test.js"></script>
<script src="js/angular-ui-router.js"></script>
<script src="js/angular-cookies.js"></script>
<script src="js/angular-growl.min.js"></script>
<script src="js/filters.js"></script>
<script src="js/xml2json.js"></script>
<script src="js/utf8_encode.js"></script>
<script src="js/moment.js"></script>
<script src="js/cordova.js"></script>
<script src="js/baclym.js"></script>
</body>
</html>
3/ in my main script at the top, i implement an event listener for device ready.
Code (beginning of baclym.js):
document.addEventListener("deviceready", function() {
var pushNotification = window.plugins.pushNotification;
console.log(pushNotification);
pushNotification.register(successHandler, errorHandler,{"senderID":"59581338115","ecb":"app.onNotificationGCM"});
function successHandler (result) {
alert('Callback Success! Result = '+result)}
function errorHandler (error) {
alert(error);
}
function onNotificationGCM (e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
console.log("Regid " + e.regid);
alert('registration id = '+e.regid);
}
break;
case 'message':
// this is the actual push notification. its format depends on the data model from the push server
alert('message = '+e.message+' msgcnt = '+e.msgcnt);
break;
case 'error':
alert('GCM error = '+e.msg);
break;
default:
alert('An unknown GCM event has occurred');
break;
}
}
}, false);
4/ I run it on my device (s4 mini, android 4.4.2)
use chrome inspect devices to debug it :
i dont get any alert message nor console messages
I eventually got an error message in cordova.js but i guess this is not linked
Uncaught ReferenceError: require is not defined cordova.js:29
I should get at least a console.log about getting into document.addEventListener, but nothing.
Thx for your advice.
As long as you have specified app.onNotificationGCM callback, you should have a global variable app with the function onNotificationGCM to be called.
You can use pushbot plugin. we use this plugin and it work perfectly.
This plugin work only on android and ios device.
So I followed this guide: http://viralpatel.net/blogs/angularjs-routing-and-views-tutorial-with-example/
But when I try to change the view nothing happens, anybody a idea what I do wrong?
This is the code I got.
Home.php:
<!DOCTYPE html>
<html ng-app="lax">
<head>
<meta name="author" content="Koen Desmedt" />
<meta name="description" content="CMS Belgium Lacrosse" />
<meta name="keywords" content='Lacrosse, BLF, Belgium' />
<meta name="googlebot" content="noarchive" />
<link href="lib/bootstrap/css/bootstrap.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
<script src="lax.js"></script>
<link href="css/style.css" rel="stylesheet">
<title>CMS Belgium Lacrosse</title>
</head>
<body>
<header class="navbar navbar-inverse navbar-fixed-top bs-docs-nav" role="banner">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation">
<ul class="nav navbar-nav navbar-left">
<li>
<a href="#/home">
<span class="glyphicon glyphicon-home"></span> BLF
</a>
</li>
<li>
Players
</li>
<li>
Club
</li>
<li>
Games
</li>
</ul>
</nav>
</div>
</header>
<div id='contentcontainer'>
<div class='container' ng-view></div>
</div>
</body>
</html>
lax.js:
var lax = angular.module('lax', []);
lax.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/home', {
templateUrl: 'views/news.php',
controller: 'NewsController'
}).
when('/players', {
templateUrl: 'views/players.php',
controller: 'PlayersController'
}).
otherwise({
redirectTo: '/home'
});
}]);
lax.controller('NewsController', function($scope) {
$scope.message = 'This is Add new order screen';
});
lax.controller('PlayersController', function($scope) {
$scope.message = 'This is Show orders screen';
});
From angular 1.2.0, ngRoute has been moved to its own module. You have to load it separately and declare the dependency.
Update your html:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-route.js"></script>
And Js:
var lax = angular.module('lax', ['ngRoute']);
For more information: http://docs.angularjs.org/guide/migration
Angular routes require the route module to be included as well. Here is the documentation that covers this.
So, I think you may be missing the:
<script src="angular-route.js"></script>
In the <head> of the page.
*Note: this module used to be part of Angular, but was moved out recently (1.2?). So, some tutorials are still assuming that $route is built-in.
Adding this would work :
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-route.js"></script>
but it will not work without internet access when running for a first time ,Therefore you should ng-route dependency to your project and refer that in your html file
How to add ng-route dependency