我是 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>
任何帮助深表感谢。