var myModule = angular.module("MyModule",[]); var MyCtrl = function($scope) { $scope.gameName = "大漠吃豆子"; } myModule.controller("MyCtrl",MyCtrl);
2、声明式注入,编写较为繁杂
var myModule = angular.module("MyModule",[]); var MyCtrl = function(funName) { funName.gameName = "大漠吃豆子"; } MyCtrl.$inject = ['$scope'];//对应各个参数名 myModule.controller("MyCtrl",MyCtrl);
3、内联式注入,压缩工具压缩也不会报错
var myModule = angular.module("MyModule",[]); myModule.controller('MyCtrl',['$scope',function($scope){ $scope.gameName = "大漠吃豆子"; } ]);原文链接:https://www.f2er.com/angularjs/149052.html