diff options
| author | Caitlin Potter | 2014-02-06 14:02:18 +0000 |
|---|---|---|
| committer | Peter Bacon Darwin | 2014-02-16 19:03:40 +0000 |
| commit | f7d28cd377f06224247b950680517a187a7b6749 (patch) | |
| tree | 20203b9f7bf60748bb752f325b1869415352a6f3 /docs/content/guide/controller.ngdoc | |
| parent | 2e641ac49f121a6e2cc70bd3879930b44a8a7710 (diff) | |
| download | angular.js-f7d28cd377f06224247b950680517a187a7b6749.tar.bz2 | |
docs(all): convert <pre>/</pre> snippets to GFM snippets
Diffstat (limited to 'docs/content/guide/controller.ngdoc')
| -rw-r--r-- | docs/content/guide/controller.ngdoc | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/docs/content/guide/controller.ngdoc b/docs/content/guide/controller.ngdoc index 77e0ac50..01f5299f 100644 --- a/docs/content/guide/controller.ngdoc +++ b/docs/content/guide/controller.ngdoc @@ -28,7 +28,7 @@ is registered. The following example shows a very simple constructor function for a Controller, `GreetingCtrl`, which attaches a `greeting` property containing the string `'Hola!'` to the `$scope`: -``` +```js function GreetingCtrl($scope) { $scope.greeting = 'Hola!'; } @@ -37,22 +37,22 @@ which attaches a `greeting` property containing the string `'Hola!'` to the `$sc Once the Controller has been attached to the DOM, the `greeting` property can be data-bound to the template: -``` -<div ng-controller="GreetingCtrl"> - {{ greeting }} -</div> +```js + <div ng-controller="GreetingCtrl"> + {{ greeting }} + </div> ``` **NOTE**: Although Angular allows you to create Controller functions in the global scope, this is not recommended. In a real application you should use the `.controller` method of your {@link module Angular Module} for your application as follows: -``` -var myApp = angular.module('myApp',[]); +```js + var myApp = angular.module('myApp',[]); -myApp.controller('GreetingCtrl', ['$scope', function($scope) { - $scope.greeting = 'Hola!'; -}]); + myApp.controller('GreetingCtrl', ['$scope', function($scope) { + $scope.greeting = 'Hola!'; + }]); ``` We have used an **inline injection annotation** to explicitly specify the dependency @@ -68,21 +68,21 @@ then available to be called from the template/view. The following example uses a Controller to add a method to the scope, which doubles a number: -``` -var myApp = angular.module('myApp',[]); +```js + var myApp = angular.module('myApp',[]); -myApp.controller('DoubleCtrl', ['$scope', function($scope) { - $scope.double = function(value) { return value * 2; }; -}]); + myApp.controller('DoubleCtrl', ['$scope', function($scope) { + $scope.double = function(value) { return value * 2; }; + }]); ``` Once the Controller has been attached to the DOM, the `double` method can be invoked in an Angular expression in the template: -``` -<div ng-controller="DoubleCtrl"> - Two times <input ng-model="num"> equals {{ double(num) }} -</div> +```js + <div ng-controller="DoubleCtrl"> + Two times <input ng-model="num"> equals {{ double(num) }} + </div> ``` As discussed in the {@link concepts Concepts} section of this guide, any @@ -270,7 +270,7 @@ Although there are many ways to test a Controller, one of the best conventions, involves injecting the {@link api/ng.$rootScope $rootScope} and {@link api/ng.$controller $controller}: **Controller Definition:** -``` +```js var myApp = angular.module('myApp',[]); myApp.controller('MyController', function($scope) { @@ -282,7 +282,7 @@ involves injecting the {@link api/ng.$rootScope $rootScope} and {@link api/ng.$c ``` **Controller Test:** -``` +```js describe('myController function', function() { describe('myController', function() { @@ -310,7 +310,7 @@ describe('myController function', function() { If you need to test a nested Controller you need to create the same scope hierarchy in your test that exists in the DOM: -``` +```js describe('state', function() { var mainScope, childScope, grandChildScope; |
