Alm*_*vic 5 javascript model-view-controller angularjs
(function () {
var app = angular.module("Sports", []);
var MainController = function($scope, $http) {
var onUser = function (response) {
obj = JSON.parse(response);
$scope.sport = angular.fromJson(obj);
};
$http.get("/api/SportApi/Get").success(function (response) {
obj = JSON.parse(response);
$scope.sport = angular.fromJson(obj);
});
};
app.controller("MainController", ["$scope", "$http", MainController]);
}());
Run Code Online (Sandbox Code Playgroud)
所以,是的,这个脚本不起作用,得到错误它找不到"主控制器作为功能"是什么问题?
编辑:错误原因在于此功能:
function consoleLog(type) {
var console = $window.console || {},
logFn = console[type] || console.log || noop,
hasApply = false;
// Note: reading logFn.apply throws an error in IE11 in IE8 document mode.
// The reason behind this is that console.log has type "object" in IE8...
try {
hasApply = !!logFn.apply;
} catch (e) {}
if (hasApply) {
return function() {
var args = [];
forEach(arguments, function(arg) {
args.push(formatError(arg));
});
return logFn.apply(console, args); //throws exception
};
}
Run Code Online (Sandbox Code Playgroud)
修正了你的小提琴。问题可能出在即时功能上。还固定ng-app和响应处理
超文本标记语言
<div ng-app="Sports">
<div ng-controller="MainController">
<table class="table table-striped table-hover">
<thead>Sport</thead>
<tr ng-repeat="x in sport">
{{sport}}
</tr>
</table>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
JS
angular
.module("Sports", [])
.controller("MainController", ["$scope", "$http", function($scope, $http) {
$http.get("https://www.googleapis.com/books/v1/volumes?q=isbn:0747532699")
.success(function (response) {
console.log(response);
$scope.sport = response.items;
});
}]);
Run Code Online (Sandbox Code Playgroud)
更新
| 归档时间: |
|
| 查看次数: |
6501 次 |
| 最近记录: |