0
運行我的測試情況下的這段代碼是給錯誤。
beforeEach(module(function($scope) {
// do something interesting with the service
//console.log($controller);
}));
控制檯出現錯誤。
debug.js:21 Uncaught Error: [$injector:modulerr] Failed to instantiate
module function ($scope) due to:
Error: [$injector:unpr] Unknown provider: $scope
任何人都可以請解釋爲什麼它是不能夠找到$範圍。如果我將它更改爲$ timeout或$ controller,它也不起作用。
更新的代碼 如果我更改代碼以這種
然後它
module(function($controllerProvider) {
// we could also access the $controllerProvider.allowGlobals() function,
// which allows us to register a controller on the window object.
$controllerProvider.register('ProductsController', function() {
// logic of the controller...
});
});
在模塊函數1中有3種傳遞參數的方法。字符串2.函數3.對象文字。 – user3045179
@ user3045179三個人都做不同的事情。如果您使用字符串參數,則會找到具有該名稱的模塊。如果您使用某個功能,它將使用該功能*創建一個新模塊*。如果您使用一個對象,它將爲每個屬性放入一個模塊。您可以查看[文檔](https://docs.angularjs.org/api/ngMock/function/angular.mock.module)以獲取更多信息。 –
你是對的,但是我認爲當你使用模塊時,它無法在提供者緩存中找到$ scope。 – user3045179