我正在查看这个 angularjs/socket.io 示例,但我想知道为什么 AppCtrl 没有 $inject 行而 MyCtrl1 有?
控制器.js:
'use strict';
/* Controllers */
function AppCtrl($scope, socket) {
socket.on('send:name', function (data) {
$scope.name = data.name;
});
}
function MyCtrl1($scope, socket) {
socket.on('send:time', function (data) {
$scope.time = data.time;
});
}
MyCtrl1.$inject = ['$scope', 'socket'];
function MyCtrl2() {
}
MyCtrl2.$inject = [];
请参阅:https ://github.com/btford/angular-socket-io-seed/blob/master/public/js/controllers.js