I have a Controller defined in my js file as below. It all works perfect until i change the placement of the "Test2Controller" controller in my javascript file. When i place the Test2Controller below the SampleController function / function declaration it gives me the below error :
Error in Chrome Dev tools :
Uncaught TypeError: Property 'controller' of object # is not a function mycontroller1.js:26 Error: Argument 'Test2Controller' is not a function, got undefined at assertArg (file:///D:/Dev/olite/workspace/olite/olite/WebContent/AngularJSDemos/mylearnings/angular.js:1039:11) at assertArgFn (file:///D:/Dev/olite/workspace/olite/olite/WebContent/AngularJSDemos/mylearnings/angular.js:1049:3) at file:///D:/Dev/olite/workspace/olite/olite/WebContent/AngularJSDemos/mylearnings/angular.js:4802:9 at file:///D:/Dev/olite/workspace/olite/olite/WebContent/AngularJSDemos/mylearnings/angular.js:4384:17 at forEach (file:///D:/Dev/olite/workspace/olite/olite/WebContent/AngularJSDemos/mylearnings/angular.js:137:20) at nodeLinkFn (file:///D:/Dev/olite/workspace/olite/olite/WebContent/AngularJSDemos/mylearnings/angular.js:4369:11) at compositeLinkFn (file:///D:/Dev/olite/workspace/olite/olite/WebContent/AngularJSDemos/mylearnings/angular.js:4015:15) at compositeLinkFn (file:///D:/Dev/olite/workspace/olite/olite/WebContent/AngularJSDemos/mylearnings/angular.js:4018:13) at compositeLinkFn (file:///D:/Dev/olite/workspace/olite/olite/WebContent/AngularJSDemos/mylearnings/angular.js:4018:13) at publicLinkFn (file:///D:/Dev/olite/workspace/olite/olite/WebContent/AngularJSDemos/mylearnings/angular.js:3920:30) ...
Working ::
var myModule = angular.module ('mymodule',[]) ;
myModule.controller('TestController', function($scope) {
$scope.message = 'Message from TestController';
});
myModule.controller('Test2Controller',function ($scope){
$scope.message = "Message from Test2Controller" ;
}) ;
myModule.controller = 'SampleController' ;
function SampleController( $scope ) {
$scope.customers = [
{name:'AAA',city:'Plano'},
{name:'BBB',city:'Plano'},
{name:'CCC',city:'Bangalore'},
{name:'DDD',city:'SanJose'},
{name:'EEE',city:'SanFO'},
{name:'FFF',city:'SanJose'}
] ;
$scope.addCustomer = addCust ;
function addCust( ) {
$scope.customers.push ( {name:$scope.customerName , city:$scope.customerCity} ) ;
} ;
}
Not working ::
var myModule = angular.module ('mymodule',[]) ;
myModule.controller('TestController', function($scope) {
$scope.message = 'Message from TestController';
});
myModule.controller = 'SampleController' ;
myModule.controller('Test2Controller',function ($scope){
$scope.message = "Message from Test2Controller" ;
}) ;
function SampleController( $scope ) {
$scope.customers = [
{name:'AAA',city:'Plano'},
{name:'BBB',city:'Plano'},
{name:'CCC',city:'Bangalore'},
{name:'DDD',city:'SanJose'},
{name:'EEE',city:'SanFO'},
{name:'FFF',city:'SanJose'}
] ;
$scope.addCustomer = addCust ;
function addCust( ) {
$scope.customers.push ( {name:$scope.customerName , city:$scope.customerCity} ) ;
} ;
}
I am currently learning angular js and kinda struck here. What could be the issue here ??