[AngularJS] Thinking Differently About Organization
1. In controller, instead of set funciton to scope, we can set function or atts to this.
And then return $scope.ControllerName = this;
2. Organization about controller and directive:
controller('appCtrl',function(){});
equals toÖ
var controllers= {};
controllers.AppCtrl = function(){
}
var app = angular.module("phoneApp", []); var phoneStuff = {}; phoneStuff.controllers = {}; phoneStuff.controllers.AppCtrl = function($scope){ this.sayHi = function () { alert('Hi'); } return $scope.AppCtrl = this; }; phoneStuff.directives = {}; phoneStuff.directives.panel = function(){ return{ restrict: 'E' }; }; app.controller(phoneStuff.controllers); app.directive(phoneStuff.directives);
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>Angular Scope &</title> <link href="foundation.min.css" rel="stylesheet"/> <script src="angular.min.js"></script> <script src="app.js"></script> </head> <body > <div ng-app="phoneApp"> <div ng-controller="AppCtrl"> <panel> <div class="button" ng-click="AppCtrl.sayHi();">Click me!</div> </panel> </div> </div> </body> </html>