Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 722 Vote(s) - 3.55 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Angularjs controller is showing undefined?

#1
I am working on node app using angularjs and cassandra.
when i go to page such as register page then front end is coming appropriately but it is showing error that controller is undefined.
**Error: error:areq
Bad Argument**

this is app.js (main js configuring file)

angular.module('app', ['ui.router'])
.config(['$urlRouterProvider', '$stateProvider',
function($urlRouterProvider, $stateProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('home', {
url: '/',
templateUrl: '/browser/views/home.html'
})
.state('register', {
url: '/register',
templateUrl: '/browser/views/register.html',
controller: 'RegisterCtrl'
})
.state('login', {
url: '/login',
templateUrl: '/browser/views/login.html',
controller: 'LoginCtrl'
})
}
]);


this is register.html file followed by the path of controller.

<div ng-controller="RegisterCtrl" class="container-fluid">
<div class="row custom-row2">
<div class="col-md-6 col-lg-6 col-sm-6">
<h4 class="sign_up">{{ title }}</h4>
<form class="form-horizontal" id="login_form" name="login_form" role="form">
<div class="form-group">
<label class="control-label col-sm-3" for="name">Name:</label>
<div class="col-sm-9">
<input ng-model="name" type="text" class="form-control" name="field1" id="name" aria-describedby="inputSuccess3Status" placeholder="Enter Your Name....">
</div>
</div>
</form>
</div>
</div>
</div>
<script type="text/javascript" src="/browser/services/validateLogin.js"></script>
<script type="text/javascript" src="/browser/controllers/registerCtrl.js"></script>

**this is the registerCtrl.js file which is coming on checking in firebug**

angular.module('app', ['ui.router'])
.controller('RegisterCtrl', ['$scope',
function($scope, RegiserService) {
$scope.title = "Sign Up";
}
]);

but **title** which has to come from the registerCtrl controller is not coming and **{{ title }}** is coming in that place.

i have gone through several times through this but didn't able to get what is going wrong in defining controller.

Reply

#2
You are recreating the module again by doing `angular.module('app', ['ui.router']).controller.` Just use the getter syntax `angular.module('app')` to get the module once the app has been created. I am assuming you are doing the same while registering the service `RegiserService` which cleans up anything else registered to the same module `app`. Once the module has been created by using the syntax `angular.module('moduleName', [..dep])` you should just get the module with the getter syntax `angular.module('app')` while registering any other subsequent entities.

Module creation (Just once):

angular.module(moduleName, [requires], [configFn]);

Module Getter (to access already created module):

angular.module(moduleName);

See [documentation](

[To see links please register here]

)

>When passed two or more arguments, a new module is created. If passed only one argument, an existing module (the name passed as the first argument to module) is retrieved.

So for example:-

angular.module('app').controller('RegisterCtrl',...
angular.module('app').service('RegiserService',...
Reply

#3
Along with redefining module as mentioned by PSL,
One more point is - what is `RegiserService`? If it is some service then the definition of controller is wrong.

correct definition is

angular.module('app', ['ui.router'])
.controller('RegisterCtrl', ['$scope', 'RegiserService',
function($scope, RegiserService) {
$scope.title = "Sign Up";
}
]);
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through