My angularjs controller function is never called. I see all the js files included in my sources, it's just not ever hitting the initialization of my controller. What is wrong with this code?
eventListCtrl.js:
eventsApp.controller('eventListCtrl', ['$scope', function ($scope) { // this code is never called alert('controller initializing'); $scope.name = "Test"; }]);
app.js:
'use strict'; var eventsApp = angular.module('eventsApp', []);
Index.cshtml:
<div ng-controller="eventListCtrl"> <div class="row"> <div class="spann11"> <h2>{{name}}</h2> </div> </div> </div> <script src="/scripts/vendor/angular.js"></script> <script src="/scripts/app.js"></script> <script src="/scripts/controllers/eventListCtrl.js"></script>
You need to do this
<html ng-app="eventsApp">
So you actually activate the module
I want to post my issue/resolution here in case anyone does the same thing as me.
<div ng-controller="coolCtrl" ng-if="VAR">
I was trying to init a controller on an element that didn't get created (because of the ng-if="var"
)
facepalm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With