javascript - AngularJS - Controller attachments to modules -


just getting grips angularjs. notice there several ways create controller, 1 method declare js function, , 1 create controller off module?

what key difference?

i.e

function greetingcontroller($scope) {   $scope.greeting = 'hola!'; } 

versus

var myapp = angular.module('myapp',[]);  myapp.controller('greetingcontroller', ['$scope', function($scope) {   $scope.greeting = 'hola!'; }]); 

using first method can reuse controller across modules separate scopes?

many thanks

regards

i

from docs:

although angular allows create controller functions in global scope, not recommended.

the key difference never use first 1 ;) reuse: combine both approaches:

function greetingcontroller($scope) {   $scope.greeting = 'hola!'; }  var myapp = angular.module('myapp',[]);  myapp.controller('greetingcontroller', ['$scope', greetingcontroller]); 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -