Statically get access to the Angular scope

This commit is contained in:
Bradlee Speice 2014-09-01 11:25:22 -04:00
parent 1911f3128a
commit 799091b6e4
3 changed files with 20 additions and 5 deletions

View File

@ -2,7 +2,7 @@
<head> <head>
<script type="text/javascript" src="file:///android_asset/dist/book-bundle.js"></script> <script type="text/javascript" src="file:///android_asset/dist/book-bundle.js"></script>
</head> </head>
<body ng-controller="BookCtrl"> <body ng-controller="BookCtrl" id="bookController">
<div ng-repeat="verse in verses"> <div ng-repeat="verse in verses">
{{ verse.text }} {{ verse.text }}
</div> </div>

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,4 @@
require 'jquery' # For using selectors to access scope
require 'angular' require 'angular'
app = angular.module('bookApp', []) app = angular.module('bookApp', [])
@ -6,4 +7,15 @@ app.controller 'BookCtrl', ['$scope', ($scope) ->
$scope.verses = [ $scope.verses = [
{'text': 'hello.'} {'text': 'hello.'}
]; ];
$scope.alert = ->
alert "Hello!"
] ]
###
Future reference: Get the controller scope like so:
angular.element($("<controller-element>")).scope().<function>
For example:
angular.element($("#bookController")).scope().<function>
###