mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-21 12:51:51 +00:00
docs(tutorial): change controllers to not have name twice
While giving the controller function a name helps with debugging, since otherwise your controller will be anonymous in stack traces, passing the name to both the `controller()` method and as the function name is confusing for beginners. Closes #4415
This commit is contained in:
parent
977e2f55de
commit
c6016a6a85
4 changed files with 6 additions and 6 deletions
|
|
@ -81,7 +81,7 @@ __`app/js/controllers.js`:__
|
||||||
|
|
||||||
var phonecatApp = angular.module('phonecatApp', []);
|
var phonecatApp = angular.module('phonecatApp', []);
|
||||||
|
|
||||||
phonecatApp.controller('PhoneListCtrl', function PhoneListCtrl($scope) {
|
phonecatApp.controller('PhoneListCtrl', function ($scope) {
|
||||||
$scope.phones = [
|
$scope.phones = [
|
||||||
{'name': 'Nexus S',
|
{'name': 'Nexus S',
|
||||||
'snippet': 'Fast just got faster with Nexus S.'},
|
'snippet': 'Fast just got faster with Nexus S.'},
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ __`app/js/controllers.js`:__
|
||||||
<pre>
|
<pre>
|
||||||
var phonecatApp = angular.module('phonecatApp', []);
|
var phonecatApp = angular.module('phonecatApp', []);
|
||||||
|
|
||||||
phonecatApp.controller('PhoneListCtrl', function PhoneListCtrl($scope) {
|
phonecatApp.controller('PhoneListCtrl', function ($scope) {
|
||||||
$scope.phones = [
|
$scope.phones = [
|
||||||
{'name': 'Nexus S',
|
{'name': 'Nexus S',
|
||||||
'snippet': 'Fast just got faster with Nexus S.',
|
'snippet': 'Fast just got faster with Nexus S.',
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ __`app/js/controllers.js:`__
|
||||||
<pre>
|
<pre>
|
||||||
var phonecatApp = angular.module('phonecatApp', []);
|
var phonecatApp = angular.module('phonecatApp', []);
|
||||||
|
|
||||||
phonecatApp.controller('PhoneListCtrl', function PhoneListCtrl($scope, $http) {
|
phonecatApp.controller('PhoneListCtrl', function ($scope, $http) {
|
||||||
$http.get('phones/phones.json').success(function(data) {
|
$http.get('phones/phones.json').success(function(data) {
|
||||||
$scope.phones = data;
|
$scope.phones = data;
|
||||||
});
|
});
|
||||||
|
|
@ -79,7 +79,7 @@ json response and parsed it for us!
|
||||||
To use a service in angular, you simply declare the names of the dependencies you need as arguments
|
To use a service in angular, you simply declare the names of the dependencies you need as arguments
|
||||||
to the controller's constructor function, as follows:
|
to the controller's constructor function, as follows:
|
||||||
|
|
||||||
function PhoneListCtrl($scope, $http) {...}
|
phonecatApp.controller('PhoneListCtrl', function ($scope, $http) {...}
|
||||||
|
|
||||||
Angular's dependency injector provides services to your controller when the controller is being
|
Angular's dependency injector provides services to your controller when the controller is being
|
||||||
constructed. The dependency injector also takes care of creating any transitive dependencies the
|
constructed. The dependency injector also takes care of creating any transitive dependencies the
|
||||||
|
|
@ -145,7 +145,7 @@ __`app/js/controllers.js:`__
|
||||||
var phonecatApp = angular.module('phonecatApp', []);
|
var phonecatApp = angular.module('phonecatApp', []);
|
||||||
|
|
||||||
phonecatApp.controller('PhoneListCtrl', ['$scope', '$http',
|
phonecatApp.controller('PhoneListCtrl', ['$scope', '$http',
|
||||||
function PhoneListCtrl($scope, $http) {
|
function ($scope, $http) {
|
||||||
$http.get('phones/phones.json').success(function(data) {
|
$http.get('phones/phones.json').success(function(data) {
|
||||||
$scope.phones = data;
|
$scope.phones = data;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,7 @@ __`app/js/controllers.js`:__
|
||||||
var phonecatControllers = angular.module('phonecatControllers', []);
|
var phonecatControllers = angular.module('phonecatControllers', []);
|
||||||
|
|
||||||
phonecatControllers.controller('PhoneListCtrl', ['$scope', '$http',
|
phonecatControllers.controller('PhoneListCtrl', ['$scope', '$http',
|
||||||
function PhoneListCtrl($scope, $http) {
|
function ($scope, $http) {
|
||||||
$http.get('phones/phones.json').success(function(data) {
|
$http.get('phones/phones.json').success(function(data) {
|
||||||
$scope.phones = data;
|
$scope.phones = data;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue