Hi I've been having some problems refactoring my controllers into their own snippets
I want the controllers to inherit the dependencies from my initial app declaration.
"use strict";
angular.module('clockOn', ['angular-contextual-date','logon','milli','mobile','ClockOnController','Auth','ngStorage'])
I need these dependencies to flow through my controllers.
angular.module('clockOn').controller('LogonController', ['$rootScope','$scope','$location','$localStorage','Auth',
function($rootScope, $scope, $location, $localStorage,Auth){
creates unknown provider errors --I'm assuming the dependencies aren't flowing down--
angular.module('clockOn',[]).controller()
creates undefined function 'controllerName' errors -In this scenario I'm assuming I'm redefining the app and hence loosing the other controllers-
Here's two of the controllers
(function (){
angular.module('clockOn',['Auth','angular-contextual-date'])
.controller('ClockOnController', ['$http','Auth','contextualDateService' ,function ($http,Auth,contextualDateService){
this.user = Auth.getTokenClaims().user; //authorised is a property of the controller
contextualDateService.config.fullDateFormats.thisMonth = "MMM d 'at' h:mm a ";
this.shifts = getShifts(this);
function getShifts(clockOnCtrl){
var date = new Date();
var curr_date = Date.now();
var week_from_now = Date.now()+"7";
$http({
method: 'GET',
url: '/shifts',
params: {"user_id":clockOnCtrl.user._id,
"start_at":curr_date,
"finish_at":week_from_now}
}).
then(function(res){
if (typeof res !== 'undefined'){
console.log(res.data);
clockOnCtrl.shifts = res.data;
}},
function(error){
console.log(error)
});
}
}]);
})();
My index file
<!DOCTYPE html>
<html class="container" ng-app="clockOn"> <!-- ng-app tells the html page which app/module it belongs too runs the store module on load-->
<head>
<meta name="viewport" content="width=device-width , initial-scale=1">
<link rel="stylesheet" type="text/css" href="../resources/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="../resources/custom.css"/>
</head>
<body>
<script type="text/javascript" src="../resources/jquery.min.js"></script>
<script type="text/javascript" src="../resources/angular.min.js"></script>
<script type="text/javascript" src="../resources/bower_components/angular-contextual-date/dist/angular-contextual-date.js"></script>
<script type="text/javascript" src="../modules/app.js"></script>
<script type="text/javascript" src="../modules/logon.js"></script>
<script type="text/javascript" src="../modules/tasks.js"></script>
<script type="text/javascript" src="../services/milli.js"></script>
<script type="text/javascript" src="../services/auth.js"></script>
<script type="text/javascript" src="../modules/mobile.js"></script>
<script type="text/javascript" src="../modules/shifts.js"></script>
<script type="text/javascript" src="../modules/layout-components.js"></script>
<script type="text/javascript" src="../resources/bower_components/ngstorage/ngStorage.min.js"></script>
<script type="text/javascript" src="../controllers/controller-clockOn.js"></script>
<script type="text/javascript" src="../controllers/controller-logon.js"></script>
<script type="text/javascript" src="../controllers/controller-tasks.js"></script>
<div class="container" ng-controller="ClockOnController as clockOnCtrl">
<div class= "" ng-controller="LogonController as logonCtrl">
<logon-form></logon-form>
<top-menu></top-menu>
<div class="page-header" ng-show="token">
<h2 class="">Welcome {{clockOnCtrl.user.name | uppercase}}
<small>You currently have {{clockOnCtrl.shifts.length}} shifts</small>
<h2>
</div>
<shifts-list></shifts-list>
<custom-footer></custom-footer>
</div>
</div>
</body>
</html>
The error Argument 'ClockOnController' is not a function, got undefined
Related
Index.html it is the main html page
I am not able to load views in angularjs though ui-route and provider seems working fine ....here is the piece of code
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<!-- build:css(client) app/vendor.css -->
<!-- bower:css -->
<!-- endbower -->
<!-- endbuild -->
<!-- build:css({.tmp,client}) app/app.css -->
<link rel="stylesheet" type="stylesheet" href="app/app.css">
<!-- injector:css -->
<!-- Google Analytics: change UA-XXXXX-X to be your site's ID -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-X');
ga('send', 'pageview');
</script>
</head>
<!--[if lt IE 9]>
<script src="bower_components/es5-shim/es5-shim.js"></script>
<script src="bower_components/json3/lib/json3.min.js"></script>
<![endif]-->
<!-- build:js({client,node_modules}) app/vendor.js -->
<!-- bower:js -->
<script type="text/javascript" src="bower_components/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="bower_components/angular/angular.js"></script>
<script type="text/javascript" src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script type="text/javascript" src="bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script type="text/javascript" src="bower_components/angular-cookies/angular-cookies.js"></script>
<script type="text/javascript" src="bower_components/angular-cookies/angular-cookies.js"></script>
<script type="text/javascript" src="bower_components/angular-resource/angular-resource.js"></script>
<script type="text/javascript" src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<script type="text/javascript" src="bower_components/angular-socket-io/socket.js"></script>
<script type="text/javascript" src="bower_components/braintree-angular/dist/braintree-angular.js"></script>
<script type="text/javascript" src="bower_components/lodash/dist/lodash.compat.js"></script>
<script type="text/javascript" src="bower_components/ng-file-upload/ng-file-upload.js"></script>
<script type="text/javascript" src="bower_components/ng-file-upload-shim/ng-file-upload-shim.js"></script>
<script type="text/javascript" src="bower_components/ngCart/dist/ngCart.js"></script>
<!-- endbower -->
<script type="javascript" src="socket.io-socket.io.js"></script>
<!-- endbuild -->
<!-- build:js(.tmp) app/app.js -->
<!-- injector:js -->
<script type="text/javascript" src="app/app.js"></script>
<script type="text/javascript" src="app/account/account.js"></script>
<script type="text/javascript" src="app/account/login/login.controller.js"></script>
<script type="text/javascript" src="app/account/settings/settings.controller.js"></script>
<script type="text/javascript" src="app/account/signup/signup.controller.js"></script>
<script type="text/javascript" src="app/admin/admin.controller.js"></script>
<script type="text/javascript" src="app/admin/admin.js"></script>
<script type="text/javascript" src="app/main/main.controller.js"></script>
<script type="text/javascript" src="app/main/main.js"></script>
<script type="text/javascript" src="app/products/products.controller.js"></script>
<script type="text/javascript" src="app/products/products.js"></script>
<script type="text/javascript" src="app/products/products.service.js"></script>
<script type="text/javascript" src="components/auth/auth.service.js"></script>
<script type="text/javascript" src="components/auth/user.service.js"></script>
<script type="text/javascript" src="components/footer/footer.directive.js"></script>
<script type="text/javascript" src="components/modal/modal.service.js"></script>
<script type="text/javascript" src="components/mongoose-error/mongoose-error.directive.js"></script>
<script type="text/javascript" src="components/navbar/navbar.controller.js"></script>
<script type="text/javascript" src="components/navbar/navbar.directive.js"></script>
<script type="text/javascript" src="components/sidebar/sidebar.controller.js"></script>
<script type="text/javascript" src="components/sidebar/sidebar.service.js"></script>
<script type="text/javascript" src="components/socket/socket.service.js"></script>
<!-- endinjector -->
<!-- endbuild -->
<!-- endinjector -->
<!-- endbuild -->
<body ng-app="meanshopApp">
<!--[if lt IE 7]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please upgrade your browser to improve your experience.</p>
<![endif]-->
<!-- Add your site or application content here -->
<div ui-view></div>
</body>
</html>
I an not able to load views in angularjs though ui-route and provider seems working fine ....here is the piece of code
app.js
var app=angular.module('meanshopApp', [
'ngCookies',
'ngResource',
'ngSanitize',
'btford.socket-io',
'ui.router',
'ui.bootstrap',
'ngFileUpload',
'ngCart',
'braintree-angular'
])
app.config(["$stateProvider", "$urlRouterProvider","$locationProvid","$httpProvider",
function ($stateProvider, $urlRouterProvider,$locationProvider, $httpProvider) {
$urlRouterProvider.otherwise("/");
$stateProvider
.state('/', {
url: "",
templateUrl: 'app/main/main.html',
controller :'MainCtrl'
})
$locationProvider.html5Mode(true);
$httpProvider.interceptors.push('authInterceptor');
}]);
app.factory('authInterceptor', function($rootScope, $q, $cookies, $injector) {
var state;
return {
// Add authorization token to headers
request: function(config) {
config.headers = config.headers || {};
if ($cookies.get('token')) {
config.headers.Authorization = 'Bearer ' + $cookies.get('token');
}
return config;
},
// Intercept 401s and redirect you to login
responseError: function(response) {
if (response.status === 401) {
(state || (state = $injector.get('$state'))).go('login');
// remove any stale tokens
$cookies.remove('token');
return $q.reject(response);
}
else {
return $q.reject(response);
}
}
};
})
app.run(function($rootScope, $state, Auth) {
// Redirect to login if route requires auth and the user is not logged in
// also if the user role doesn't match with the one in `next.authenticate`
$rootScope.$on('$stateChangeStart', function(event, next) {
if (next.authenticate) {
var loggedIn = Auth.isLoggedIn(function(role) {
if (role && role === next.authenticate) {
return; // logged in and roles matches
}
event.preventDefault();
if(role) {
// logged in but not have the privileges (roles mismatch)
$state.go('onlyAdmin');
} else {
// not logged in
$state.go('login');
}
});
}
});
})
I am not able to load views in angularjs though ui-route and provider seems working fine ....here is the piece of code
main.html
<navbar></navbar>
<header class="hero-unit" id="banner">
<div class="container">
<h1>MEANshop</h1>
<p class="lead">The MEAN stack one stop shop</p>
<img src="assets/images/logo.png" alt="the meanstack shop">
</div>
</header>
<div class="container">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Featured Products:</h1>
<ul class="nav nav-tabs nav-stacked col-md-4 col-lg-4 col-sm-6" ng-repeat="product in products">
<li><a ui-sref="viewProduct({id: product._id})" tooltip="{{product.description}}">
{{product.title}} -
<span class="text-muted">{{product.price | currency}}</span>
</a></li>
</ul>
</div>
</div>
</div>
<footer></footer>
I an not able to load views in angularjs though ui-route and provider seems working fine ....here is the piece of code
maincontroller
'use strict';
angular.module('meanshopApp')
.controller('MainCtrl', function($state,$scope,$http, socket, Product) {
alert("helloeen");
$scope.products = Product.query();
});
After going through your code, i came across some issues which is basically restricting the main.html to load. Kindly fix below issues in you app.js file
$locationProvider spelling is incorrect
url while defining state should not be blank.
Do you need to enable htmlMode5 because i have faced lot of issues while enabling this.You can use $locationProvider.hashPrefix('') to make URL better;
app.config(["$stateProvider",
"$urlRouterProvider","$locationProvider","$httpProvider",
function ($stateProvider, $urlRouterProvider,$locationProvider, $httpProvider) {
$urlRouterProvider.otherwise("/");
$stateProvider
.state('/', {
url: "/",
templateUrl: 'app/main/main.html',
controller :'MainCtrl'
})
$locationProvider.hashPrefix('');
$httpProvider.interceptors.push('authInterceptor');
}]);
I trying to include chosen js library in to my project where i use select html tag. Its working with simple selection list, but when i try to populate list using angular js ng-repeat , its not working. Please help me where i gone wrong. below is my code.
<html>
<head>
<title></title>
<link rel="stylesheet" href="docsupport/style.css">
<link rel="stylesheet" href="docsupport/prism.css">
<link rel="stylesheet" href="chosen.css">
</head>
<body ng-app="testapp" ng-controller = "testController">
<select chosen class="chosen-select" ng-options = "cust.CustName for cust in customers">
</select>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.js" type="text/javascript"></script>
<script src="chosen.jquery.js" type="text/javascript"></script>
<script src="docsupport/prism.js" type="text/javascript" charset="utf-8"></script>
<script src="docsupport/init.js" type="text/javascript" charset="utf-8"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"> </script>
<script type="text/javascript">
var app = angular.module('testapp', []);
app.controller('testController',['$scope','$http', function($scope,$http)
{
$http.get("php/getCustomerList.php")
.then (function(response)
{
$scope.customers = response.data;
});
}]);
</script>
</body>
</html>
I think you have to use ng-model with ng-options in your select tag.
Try like below code:
<select chosen class="chosen-select" ng-model="mySelectBox" ng-options = "cust.CustName for cust in customers">
You can check my running snippet here. I removed your api call and enter value manually
<html>
<head>
<title></title>
<link rel="stylesheet" href="docsupport/style.css">
<link rel="stylesheet" href="docsupport/prism.css">
<link rel="stylesheet" href="chosen.css">
</head>
<body ng-app="testapp" ng-controller = "testController">
<select chosen class="chosen-select" ng-model="mySelect" ng-options = "cust.CustName for cust in customers">
</select>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.js" type="text/javascript"></script>
<script src="chosen.jquery.js" type="text/javascript"></script>
<script src="docsupport/prism.js" type="text/javascript" charset="utf-8"></script>
<script src="docsupport/init.js" type="text/javascript" charset="utf-8"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"> </script>
<script type="text/javascript">
var app = angular.module('testapp', []);
app.controller('testController',['$scope','$http', function($scope,$http)
{
$scope.customers = [{'CustName':'Angular'},{'CustName':'JavaScript'},{'CustName':'Java'}];
}]);
</script>
</body>
</html>
<html>
<head>
<script type="text/javascript" src="js/angular/angular.js"></script>
<script type="text/javascript" src="js/angular/angular-route.js"></script>
<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<title></title>
<meta name="author" content="Stanislau">
<link href="css/style.css" rel="stylesheet">
</head>
<body ng-app="testApp">
<div ng-controller="testCtrl">
{{Message}}
</div>
</body>
</html>
main.js code
var app = angular.module('testApp', ['ngRoute']);
app.controller('testCtrl', function($scope){
$scope.Message = '123';
});
Error:
angular.js:68 Uncaught Error: [$injector:modulerr] Failed to instantiate module testApp due to:
Error: [$injector:nomod] Module 'testApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.6.1/$injector/nomod?p0=testApp
if code:
<html>
<head>
<script type="text/javascript" src="js/angular/angular.js"></script>
<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<title></title>
<meta name="author" content="Stanislau">
<link href="css/style.css" rel="stylesheet">
</head>
<body ng-app="testApp">
<div ng-controller="testCtrl">
{{Message}}
</div>
</body>
</html>
main.js code:
var app = angular.module('testApp', []);
app.controller('testCtrl', function($scope){
$scope.Message = '123';
});
The error is the same!!
Test version address: http://zadanie.salesdep.by/
Code is working fine.Please check the library reference path
<div ng-app="testApp" ng-controller="testCtrl">
<div ng-controller="testCtrl">
{{Message}}
</div>
</div>
<script>
var app = angular.module('testApp', []);
app.controller('testCtrl', function($scope){
$scope.Message = '123';
});
</script>
Hello guys for 2 days i am trying to call a react component from html and every time it throw me that error "Error: Cannot find react component MyReact"
so that is my html.I would be very grateful if someone help me
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" href="css/datepicker.css">
<link rel="stylesheet" href="css/angular-material.min.css">
<script src="react-15.3.0.js"></script>
<script src="react-dom-15.3.0.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.js"></script>
</head>
<body ng-app="listOfDiaries" ng-controller="myCtrl as ctrl">
<react-component name="MyReact"></react-component>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-animate.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-aria.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angular_material/1.1.0-rc2/angular-material.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.6/angular-messages.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src = 'js/bootstrap.js'></script>
<script src="js/ngReact.js"></script>
<script type="text/babel" src="tutorial.js"></script>
<script src = 'config.js'></script>
<!--data-toggle="modal" data-target="#{{myprops.id}}"-->
</body>
</html>
that is tutorial file:
var MyReact = React.createClass({
render: function() {
console.log("qweqw");
return(
<div>
<h2>georgi</h2>
</div>
);
}
});
app.value('MyReact',MyReact);
and my config file:
var app = angular.module('listOfDiaries', ['react','ngMaterial','ngMessages']);
app.controller('myCtrl', ["$scope", "myFirstService", function ($scope, myFirstService) {
var self = this;
//and directive and so on..
I don't program Angular; but looking at the code in the app.directive statement; if that code is run immediately MyReact is not defined. Try switch the MyReact class and the app.directive block.
I'm trying to build up a REST client written in AngularJS that uses $resources for consuming the REST service and ng-grid library for the User Interface.
By using just the $resource module dependency my code works, however if I introduce also the ngGrid dependency it just displays an empty div.
I've little experience with modules but the syntax seems correct....
<link rel="stylesheet" type="text/css" href="ng-grid.css" />
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="jquery-1.9.1.js"></script>
<script type="text/javascript" src="angular.js"></script>
<script type="text/javascript" src="ng-grid-2.0.7.min.js"></script>
<script type="text/javascript" src="angular-resource.js"></script>
<script language="javascript">
angular.module('myApp',['ngResource'], ['ngGrid']);
function Ctrl($scope,$resource) {
var restservice = $resource(
'http://host/myapp/json', {
}, {
query: { method: 'GET', isArray: true }
}
);
$scope.gridOptions = restservice.query();
};
</script>
</head>
<body>
<div ng-app="myApp">
<div ng-controller="Ctrl">
<div class="gridStyle" ng-grid="gridOptions"></div>
</div>
</div>
</body>
Do you see any error in the above code ?
Thanks!
You don't need to pass in a separate array for each module, nest them under one array like this.
angular.module('myApp',['ngResource', 'ngGrid']);