Infinite Scrolling not working for ngInfiniteScrol - javascript

I am new to AngularJS and trying to implement infinite scrolling using https://github.com/sroze/ngInfiniteScroll.
However my code gives me the following error on console on the browser. What is confusing me is that it is pointing to the code in the library I am using and not my code. IS this a bug from my side or in the some linking error?
Has anyone else used this and faced a similar issue. I cannot really post my source code since its quite big at this point and I am using the infinite-scroll when I am using the ng-repeat directive to list results. Thank you
ng-infinite-scroll.js:42 Uncaught ReferenceError: app is not defined
Here is my app.js
'use strict';
/**
* #ngdoc overview
* #name angularSocketNodeApp
* #description
* # angularSocketNodeApp
*
* Main module of the application.
*/
// Added 'ngInfiniteScroll' below
angular.module('angularSocketNodeApp', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch',
'ui.bootstrap',
'btford.socket-io',
'angular-md5',
'ngInfiniteScroll'
])
.factory('theSocket', function(socketFactory) {
var myIoSocket = io.connect('/');
var theSocket = socketFactory({
ioSocket: myIoSocket
});
return theSocket;
})
.config(function($routeProvider) {
$routeProvider
.when('/main', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.when('/about', {
templateUrl: 'views/about.html',
controller: 'AboutCtrl'
})
.when('/search', {
templateUrl: 'views/search.html',
controller: 'SearchCtrl'
})
.when('/search/:query', {
templateUrl: 'views/search.html',
controller: 'SearchCtrl'
})
.when('/teacher', {
templateUrl: 'views/teacher.html',
controller: 'TeacherCtrl'
})
.when('/class/:id', {
templateUrl: 'views/class.html',
controller: 'ClassCtrl'
})
.when('/signup', {
templateUrl: 'views/signup.html',
controller: 'SignUpCtrl'
})
.when('/login/teacher', {
templateUrl: 'views/loginteacher.html',
controller: 'LogInTeacherCtrl'
})
.when('/login/student', {
templateUrl: 'views/loginstudent.html',
controller: 'LogInStudentCtrl'
})
.when('/u/:username/:classname', {
templateUrl: 'views/class.html',
controller: 'ClassCtrl'
})
.otherwise({
redirectTo: '/search'
});
});

Related

Angular router is not working but there is no errors aswell

I am new to angularjs. I have two router files auth_router.js and teacher_router.js. the auth_router.js is working fine but the teacher_router.js is not working. the code is below:
app.js file
angular.module("learn_mart", ['ngRoute', 'ngCookies'])
.run(function($rootScope, $cookies) {
$rootScope.baseurl = "http://localhost/lm/auth.html#";
$rootScope.userrole = $cookies.get('userrolecookie');
$rootScope.activetab = $cookies.get('activetabcookie');
$rootScope.redirectologin = function(role) {
$cookies.put('activetabcookie', 1);
$cookies.put('userrolecookie', role);
window.location = $rootScope.baseurl + '/' + role + "_login";
};
});
auth_router.js file
angular.module("learn_mart")
.config(function($routeProvider) {
$routeProvider
.when("/sub_login", {
controller: "subscriber_login",
templateUrl: 'views/auth/subscriber_login.html'
})
.when("/sub_register", {
controller: "subscriber_registration",
templateUrl: 'views/auth/subscriber_registration.html'
})
.when("/tech_login", {
controller: "teacher_login",
templateUrl: 'views/auth/teacher_login.html'
})
.when("/tech_register", {
controller: "teacher_registration",
templateUrl: 'views/auth/teacher_registration.html'
})
.when("/shop_login", {
controller: "shop_login",
templateUrl: 'views/auth/shop_login.html'
})
.when("/shop_register", {
controller: "shop_registration",
templateUrl: 'views/auth/shop_registration.html'
})
});
teacher_router.js
angular.module("learn_mart")
.config(function($routeProvider) {
$routeProvider
.when("/teacher_course", {
controller: "show_courses_teacher",
templateUrl: "views/auth/shop_login.html"
})
});
There is no issue's with the file inclution. Also there is no errors shown in the developer console.

controller not a function AngularJS

I have a problem. my routes do not find my controllers except /vehicules
app.js
angular.module('myApp', ['ngRoute', 'ui.grid']);
angular.module('myApp').config(function($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl: 'views/main.html',
controller: ''
})
.when('/vehicules', {
templateUrl: 'views/vehicules.html',
controller: 'VehiculeCtrl'
})
.when('/vehicule/:id', {
templateUrl: 'views/vehicule.html',
controller: 'VoirVehiculeCtrl'
})
.when('/agents', {
templateUrl: 'views/agents.html',
controller: 'AgentsCtrl'
})
.when('/agences', {
templateUrl: 'views/agences.html',
controller: 'AgencesCtrl'
})
.when('/status', {
templateUrl: 'views/status.html',
controller: 'StatusCtrl'
})
.otherwise({
redirectTo: '/'
});
});
VoirVehiculeCtrl.js
angular.module('myApp').controller('VoirVehiculeCtrl', function($scope) {});
my tree:
Javascript
controllers
VehiculeCtrl.js
VoirVehiculeCtrl.js
App.js
Views
please help me !! and sorry for my english xD

Angular $routeProvider to handle different URLs differently

In angular, is there a method to load different views & controllers when the routes are basically the same, but the actual string in the route is different?
In terms of routing, if the top level route parameter is being already used, is there way to load different View & Controller based on the different route parameter?
Below is what I was trying:
app.config(['$routeProvider',
function($routeProvider) {
$routeProvider
.when("/", {
templateUrl: "app/components/0_home/homeView.html",
controller: "HomeController"
}) // Home
.when("/about", {
templateUrl: "app/components/1_about/aboutView.html",
controller: "AboutController"
}) // About
/*(...Bunch of other .whens)*/
//Project
.when("/project/:projectId", {
templateUrl: "app/components_project/0_home/homeView.html",
controller: "ProjectHomeController"
})
.when("/project/:projectId/HOME", {
templateUrl: "app/components_project/0_home/homeView.html",
controller: "ProjectHomeController"
})
.when("/project/:projectId/FLOORPLAN", {
templateUrl: "app/components_project/1_floorplans/floorplanView.html",
controller: "FloorplanController"
}) // Floorplan
.when("/404", {
templateUrl: "app/components/404.html"
}) // else 404
.otherwise({
redirectTo: '/404'
});
}
]);
I wanted to load
app/components_project/0_home/homeView.html
when routeProvider is
/project/:projectId/HOME
and load
app/components_project/1_floorplans/floorplanView.html
when routeProvider is
/project/:projectId/FLOORPLAN
Or is there any better way to handle this kind of situation?

AngularJS, $routeProvider

I'm trying to learn how routes work in AngularJS to make a little application that allows users to login and write comments in a live feed. However the whole concept of routes is a bit blurry for me atm and i can't get this right.
My standard index.html containing an ng-view and necessary scripts.
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular-route.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.js"></script>
<script src="//cdn.firebase.com/js/client/1.0.21/firebase.js"></script>
<script src="//cdn.firebase.com/libs/angularfire/0.8.2/angularfire.js"></script>
<script src="//cdn.firebase.com/js/simple-login/1.6.3/firebase-simple-login.js"></script>
<script src="controller.js"></script>
<title>Test Login App</title>
</head>
<body>
<div class="container">
<div ng-view></div>
</div>
</body>
</html>
My controller containing module and routeprovider.
var myApp = angular.module('myApp', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch',
'firebase',
'firebase.utils',
'simpleLogin'
]);
myApp.config(function($routeProvider) {
$routeProvider.
when('/', { controller: handleCtrl, templateUrl: 'handler.html' }).
when('/chatt', { controller: MyController, templateUrl: 'chat.html' }).
when('/login', { controller: loginCtrl, templateUrl: 'login.html' }).
otherwise({ redirectTo: '/handler' });
});
myApp.config(['$locationProvider', function($locationProvider) {
$locationProvider.html5Mode(true);
}])
myApp.controller('MyController', ['$scope', '$firebase',
function($scope, $firebase) {
//CREATE A FIREBASE REFERENCE
var ref = new Firebase("https://ivproj.firebaseio.com/");
// GET MESSAGES AS AN ARRAY
$scope.messages = $firebase(ref).$asArray();
//ADD MESSAGE METHOD
$scope.addMessage = function(e) {
//LISTEN FOR RETURN KEY
if (e.keyCode === 13 && $scope.msg) {
//ALLOW CUSTOM OR ANONYMOUS USER NAMES
var name = $scope.name || 'anonymous';
//ADD TO FIREBASE
$scope.messages.$add({
from: name,
body: $scope.msg
});
//RESET MESSAGE
$scope.msg = "";
}
}
}
]);
The $routeprovider function should direct me to handler that is a simple .html file containing two buttons that in turn redirects to other htmls.
I think you have the syntax of the otherwise call in your config section wrong. Change what you have for this instead:
otherwise('/handler');
hope this helps...
you are missing '' in controller part. correct code should look like -
myApp.config(function($routeProvider) {
$routeProvider.
when('/', { controller: 'handleCtrl', templateUrl: 'handler.html' }).
when('/chatt', { controller: 'MyController', templateUrl: 'chat.html' }).
when('/login', { controller: 'loginCtrl', templateUrl: 'login.html' }).
otherwise({ redirectTo: '/handler' });
});
Make sure that you are referring the correct path in templateUrl.
and look at my earlier post to get a better idea - How to navigate in Angular App
myApp.config(function($routeProvider) {
$routeProvider.
when('/', { controller: 'handleCtrl', templateUrl: 'handler.html' }).
when('/chat', { controller: 'MyController', templateUrl: 'chat.html' }).
when('/login', { controller: 'loginCtrl', templateUrl: 'login.html' }).
otherwise({ redirectTo: '/handler' });
});
The $routeProvider.when() method in the above code actually creates a route with the given configuration. And the three .when()'s are creating three different routes.
But in your $routeProvider.otherwise('/handler'), you are telling angular to go to a route called /handler if the user tries to navigate anywhere outside the configured routes.
The mistake you are doing here is, you did not define a route at /handler. So you need to first define that route and then use it in .otherwise().
Try changing your configuration to reflect the below.
myApp.config(function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider.
when('/handler', { controller: 'handleCtrl', templateUrl: 'handler.html' }).
when('/chat', { controller: 'MyController', templateUrl: 'chat.html' }).
when('/login', { controller: 'loginCtrl', templateUrl: 'login.html' }).
otherwise({ redirectTo: '/handler' });
});

Route AngularJS app without changing URI

I am trying to create an Angular API which should be able to be integrated on any webpage. I have a frontApp using AngularJS and a backend which uses Laravel 4.
The problem is that my routing look like this at the moment :
angular.module('FrontApp').config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/home', {
templateUrl: 'views/home.html',
controller: 'HomeCtrl'
})
.when('/login', {
templateUrl: 'views/login.html',
controller: 'LoginCtrl'
})
.when('/register', {
templateUrl: 'views/register.html',
controller: 'RegisterCtrl'
})
.when('/members', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.when('/apinotfound', {
templateUrl: 'views/api.html'
})
.otherwise({
redirectTo: '/login'
});
}]);
But since my App will be integrated on a webpage whose URI can not changed, I can not use this routing system. I was wondering if a trick would be possible, to keep those routes in a variable maybe, and then route my App without changing the URI of the page?

Categories