我想建立一个应用程序Angularjs,我有我的控制器的麻烦。
I'm trying to build an Angularjs application and I'm having trouble with my controller.
'use strict';
/* Controllers */
angular.module('myApp.controllers', []).
controller('AppCtrl', function ($scope, $http) {
}).
controller('indexCTRL', function ($scope) {
$http.get('/api/frettir').
success(function(data, status, headers, config) {
$scope.posts = data;
});
});
但是当我运行一个错误出现说$ HTTP没有定义。我可以改进?
But when I run it an error appears saying $http is not defined. What can I improve?
您需要使用它的控制器注入 $ HTTP
服务。我喜欢这个非常precise 内嵌语法,以避免出现问题,如果你的code去通过minifiers。
You need to inject the $http
service in the controllers you use it. I like this very precise inline syntax which will avoid problems if your code goes through minifiers.
controller('indexCTRL', ['$scope', '$http',
function($scope, $http) {
//...your code
}
])
上一篇:AngularJS NG-重复阵列,每件独特的$范围变量阵列、变量、每件、独特
下一篇:控制或禁用浏览器后退按钮JavaScript或AngularJS按钮、浏览器、AngularJS、JavaScript