我正在关注Brad Daley关于角度框架的书。在控制台中,它带我到以下
我有一个简单的Angular 1.7.8应用程序,但是我不断遇到以下错误;
错误:$ injector:unpr 未知提供者。 网址:https://code.angularjs.org/1.7.8/docs/error/$injector/unpr?p0=configTimeProvider%20%3C-%20configTime%20%3C-%20controllerA
var configApp = angular.module('configApp1', []);
configApp.config(function ($provide) {
$provide.value = ("configTime", new Date());
$provide.value = ("runTime", new Date());
for (var i = 0; i < 10000000; i++) {
var y = Math.sqrt(Math.log(i))
};
})//end config
configApp.run(function(configTime,runTime){
runTime.setTime(new Date().getTime());
});
configApp.controller('controllerA', ['$scope', 'configTime', 'runTime',
function ($scope, configTime, runTime) {
$scope.configTime = configTime;
$scope.runTime = runTime;
}])
HTML如下
<!DOCTYPE html>
<html ng-app = 'configApp1'>
<head>
<title>Configuration Run Blocks in Angular</title>
</head>
<body>
<div ng-controller = 'controllerA' >
<h2>Config Time</h2>
{{configTime}}
<h2></h2>
<hr>
<h2>Run Time</h2>
{{runTime}}
<h2></h2>
</div>
<script src="../angular/angular.min.js"></script>
<script src="js/config.js"></script>
</body>
</html>
答案 0 :(得分:0)
调用someArray[3] = desired_value
作为$provide.value
服务的一种方法:
$provide
有关更多信息,请参见