Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am new to both Require and Angular. My question is how to access a controller on ng-click if the controller is hosted in a module. In My case I have to following files:

-- This is controller factory --

'use strict';
define(['angular', 'controllers/authenticationController'], function (angular, authenticationController) {
    var controllers = angular.module('myapp.controllers', ['myapp.services']);
    controllers.controller('authenticationController', authenticationController);
    return controllers;
});

-- This is the controller --

'use strict';
define(function () {
    var controller = function ($scope, authenticationService) {
        $scope.signin = function() {
            authenticationService.signin();
        }
    };
    controller.$inject = ['$scope', 'authenticationService'];

    return controller;
});

Here is the html part.

<!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>

Any help is much appreciated.

share|improve this question
    
what method is called by ng-click? –  Roy Truelove Apr 26 '13 at 18:51
    
I apologize, forgot to paste the entire code. The method that has to be called is 'signin'. –  Mihai H Apr 26 '13 at 19:01
    
Can you post your HTML as well? Want to see where the controller is defined there. –  Roy Truelove Apr 26 '13 at 19:35
    
I just added the html. For sure the way I am doing it is not the right way. –  Mihai H Apr 27 '13 at 5:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.