我只是碰到一个示例代码对角JS控制器继承从这个网址http://viralpatel.net/blogs/angularjs-controller-tutorial/角JS控制器继承问题
这里是代码,我只是不明白一个组成部分。
<div ng-controller="BMWController">
My name is {{ name }} and I am a {{ type }}
<button ng-click="clickme()">Click Me</button>
</div>
<script>
function CarController($scope) {
$scope.name = 'Car';
$scope.type = 'Car';
$scope.clickme = function() {
alert('This is parent controller "CarController" calling');
}
}
function BMWController($scope, $injector) {
$injector.invoke(CarController, this, {$scope: $scope});
$scope.name = 'BMW';
}
</script>
1)我只是不明白这行代码$injector.invoke(CarController, this, {$scope: $scope});
2),其中价值范围BMWController范围和$范围CarController范围是什么?
3)有两个范围{$ scope:$ scope}一个在左边和一个在右边哪一个与有关BMWController & CarController scope?
4)为什么在调用函数中使用此关键字? 5)请帮我理解这一行$ injector.invoke(CarController,this,{$ scope:$ scope});
感谢
我如何知道服务是单身人士?我们可以写任何代码证明服务是单身...寻找指导。谢谢 – Mou
当我们调用'$ injector.invoke()'给我想法时,为什么我们需要传递'this关键字' – Mou
他们是按定义单身。看看文档(https://docs.angularjs.org/guide/services)。 –