In AngularJS, methods can be called from within templates without a directive or routeProvider to bind a region?
My particular problem is that my main controller (AppCtrl) is located on the body of my index page. In the index, I use ngView to pull patterns according to routing. Each routeProvider has its own controller, with the exception of the default template. I suggested that due to region inheritance, I could use the methods defined using AppCtrl from the template, but I'm trying to just make a simple alert or console.log is not registering anything. I know that the $ region fits the pattern because my data is displayed correctly.
This seems to be a problem with $ scope, but I'm not sure how to solve it. Do I need to create a directive to explicitly bind them?
index.html
<body ng-controller="AppCtrl"> <div ng-view></div> </body>
app.js
var myApp = angular.module('myApp', []) .config(function($routeProvider) { .when('/', { templateUrl: 'partials/list.html' }), .when('/info/:id, { templateUrl: 'partials/info.html' controller: 'InfoCtrl' }); });
controllers.js
var controllers = {}; controllers.AppCtrl = function($scope, $location, Factory) { ... $scope.doSomething = function() { alert('hello'); }; }; myApp.controller(controllers);
list.html
<a href="#" ng-click="doSomething()">Do Something</a> // no response
source share