0

I am new to angularjs and I have been trying out few basic tutorials and I noticed some discrepancy on how controller is declared and used thus I wanted clarification , for example in this JSfiddle link - http://jsfiddle.net/dakra/U3pVM/ the user has defined the controller as the function name which works perfectly fine for version 1.0.3 . I am using 1.3.15 version of angular and this approach isn't working for me

<html ng-app="myapp">

AngularJS data binding

<div data-ng-controller="SimpleController">

    Name :
    <br/>
    <input type="text" ng-model="name"/>{{name |uppercase}}
    <div>
        <ul>
            <li ng-repeat="personName in names">{{personName}}</li>
        </ul>

    </div>

</div>
<script src="node_modules/angular/angular.min.js"></script>

<script>

function SimpleController($scope) {
    $scope.names =['test1','test2','new'];
}

The above code just isn't working as it's showing an error of SimpleController being undefined function.

where as when I add this code instead of the above function, it works -

    var app = angular.module('myApp', []);
app.controller('SimpleController', function($scope) {
    $scope.names = ['test1','test2'];
});

Thanks,

1
  • One concern for me when using: function MyController($scope) { ... } is that if you will be minifying your code for production, your controller will not be found due to a change in their variable names. Commented Jun 3, 2015 at 15:53

1 Answer 1

1

The simple declaration of controllers via

function MyCtrl($scope) {

}

was removed in Angular 1.3. Breaking changes: http://wildermuth.com/2014/11/11/Angular_1_3_and_Breaking_Change_for_Controllers

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.