我是一个angular JS的初学者,在教程中找到了这段代码。
var phonecatApp = angular.module('phonecatApp', []);
phonecatApp.controller('PhoneListCtrl', function($scope) {
$scope.phones = [
{'name': 'Nexus S',
'snippet': 'Fast just got faster with Nexus S.'},
{'name': 'Motorola XOOM™ with Wi-Fi',
'snippet': 'The Next, Next Generation tablet.'},
{'name': 'MOTOROLA XOOM™',
'snippet': 'The Next, Next Generation tablet.'}
];
});
这段代码工作得很好,但我想知道
$scope
变量的作用域是如何工作的。从代码中看,$scope
似乎是一个局部变量,其作用域仅限于函数内部。那么为什么我不能更改
$scope
变量的名称呢?如果我在函数内部所有出现的地方都更改变量名,它似乎无法正常工作。