Last active
March 17, 2016 19:49
-
-
Save JeffryGonzalez/b42222ea696575e1b260 to your computer and use it in GitHub Desktop.
Angular scope identifier stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html xmlns="http://www.w3.org/1999/xhtml"> | |
| <head> | |
| <title></title> | |
| <style> | |
| .debug .ng-scope { | |
| border: .8px dotted red; | |
| padding: 5px; | |
| margin: 3px; | |
| background-color: rgba(63, 202, 192, 0.4); | |
| border-radius: 10px; | |
| box-shadow: black -3px 0 9px; | |
| } | |
| .debug .ng-scope::before { | |
| content: "SCOPE"; | |
| color: black; | |
| font-size: 1.2em; | |
| text-shadow: black 3px 0 4px; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div ng-app="app" class="debug" > | |
| <div ng-controller="ControllerOne as parent"> | |
| <h3>{{parent.message}}</h3> | |
| <input ng-model="parent.thing" /> | |
| <h1>{{parent.thing}}</h1> | |
| <div ng-controller="ControllerTwo as c2"> | |
| <h3>{{parent.message}}</h3> | |
| <input ng-model="c2.thing" /> | |
| <h1>{{c2.thing}}</h1> | |
| <input type="button" value="Click me for a good time!" ng-click="c2.sayHi()" /> | |
| <div ng-controller="ControllerTwo as c2"> | |
| <h3>{{parent.message}}</h3> | |
| <input ng-model="c2.thing" /> | |
| <h1>{{c2.thing}}</h1> | |
| <input type="button" value="Click me for a good time!" ng-click="c2.sayHi()" /> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <script src="Scripts/angular.min.js"></script> | |
| <script> | |
| var app = angular.module("app", []); | |
| app.config(function($compileProvider) { | |
| $compileProvider.debugInfoEnabled(location.search.substring(1).indexOf('debug') >= 0); | |
| }); | |
| app.controller("ControllerOne", function ($scope) { | |
| var vm = this; | |
| vm.message = "Jeff Was Here"; | |
| $scope.$on("HELLO_MESSAGE", function () { | |
| alert("The controller one got the event!"); | |
| }); | |
| }); | |
| app.controller("ControllerTwo", function ($rootScope) { | |
| var vm = this; | |
| vm.sayHi = function () { | |
| $rootScope.$broadcast("HELLO_MESSAGE"); | |
| }; | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment