angularjs - What is the benefit of defining Angular app? -
in angularjs tutorials, angular app defined as:
myapp = angular.module("myapp",[]);
but can without it. difference can see when define controller, can't utilize idiom:
myapp.controller("myctrl",function(){ })
but has utilize
function myctrl (){}
is there other benefits of defining myapp explicitly, given create single app site? if don't define myapp, modules attached to?
if there is, how can recreate myapp in testing jasmin?
you can define controllers in (at least) 3 ways:
define controller global var (stored on window
object)
function ctrl() {}
which same doing:
window.ctrl = function () {}
create module , utilize returned instance create new controllers:
var app = angular.module('app', []); app.controller('ctrl', function() {});
create controllers straight on module without storing references (the same 2
without using vars):
angular.module('app', []); angular.module('app').controller('ctrl', function() {});
from angular's point of view, same, can mix them , work. difference alternative 1
uses global vars while in options 2
, 3
controllers stored within angular's private object.
angularjs
No comments:
Post a Comment