我是Require和Angular的新手。我的问题是如果控制器托管在模块中,如何在ng-click上访问控制器。在我的情况下,我必须关注文件:
- 这是控制器工厂 -
'use strict';
define(['angular', 'controllers/authenticationController'], function (angular, authenticationController) {
var controllers = angular.module('myapp.controllers', ['myapp.services']);
controllers.controller('authenticationController', authenticationController);
return controllers;
});
- 这是控制器 -
'use strict';
define(function () {
var controller = function ($scope, authenticationService) {
$scope.signin = function() {
authenticationService.signin();
}
};
controller.$inject = ['$scope', 'authenticationService'];
return controller;
});
这是html部分。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test Project Setup</title>
<meta charset="utf-8"/>
<link href="scripts/lib/Bootstrap/css/bootstrap.css" rel="stylesheet" />
<link href="scripts/lib/bootstrap/css/bootstrap-responsive.css" rel="stylesheet" />
</head>
<body>
<div ng-controller="authorizationController">
<button ng-click="signin">Do the signin here</button>
</div>
<div ng-view></div>
<script type="text/javascript" data-main="scripts/main" src="scripts/lib/require/require.js"></script>
</body>
</html>
非常感谢任何帮助。