從這個網址https://github.com/angular/angular-seed/blob/master/app/js/app.js,我得到了像下面這樣的控制器。關鍵字「this」裏面的角度js控制器
function WineListCtrl(Wine) {
this.wines = Wine.query();
}
到目前爲止,我一直在做的角度是定義一個控制器$ scope注入。所以,我想,改變上述控制器
function WineListCtrl(Wine, $scope) {
console.log($scope, this)
this.wines = Wine.query();
}
但是,這給了一個錯誤錯誤:未知提供商'$scope'
。
我這裏有三個問題:
- 爲什麼控制器的
$scope
沒有注入。 this
裏面的WineListCtrl
是指$scope
。- Angular中的大部分錯誤格式爲「XXXX的未知提供者 」。如果螢火蟲這麼說,我應該尋找什麼?
。我不混淆任何文件。即使在添加註入註釋之後,仍然會在控制器下面拋出相同的錯誤。我怎樣才能訪問'$ scope'。請查看http:// plnkr上的文件。co/edit/F3WOir8KmEAcqSrX0bRI?p =預覽 – rajkamal 2013-02-28 00:12:23
請參閱http://plnkr.co/edit/K2Q61Bw0w9PnjRdCtvWY?p=preview。你的問題之一是你需要注入$ routeProvider而不是$ route。另外,您不能在控制器中注入$ routeProvider。請參閱[$ route](http://docs.angularjs.org/api/ng.$route)頁面上的示例。如果你想使用/注入$資源,你必須包含另一個.js文件。請參閱[$資源頁面]上的Disqus評論(http://docs.angularjs.org/api/ngResource.$resource)。 – 2013-02-28 01:07:06
謝謝,解決了這個問題。 – rajkamal 2013-02-28 02:50:29