0

I was playing around with some jsfiddle examples and changed it for some tests. Unfortunately it is not working anymore and i have no clue why. Can anyone have a quick look at this fiddle and give me a hint:

http://jsfiddle.net/w8LrL8xr/2/

javascript:

var myApp = angular.module("myApp");

myApp.controller("MyCtrl", function($scope) {

$scope.fonts = [
    {title: "Arial" , text: 'Url for Arial' },
    {title: "Helvetica" , text: 'Url for Helvetica' }
];
$scope.change= function(option){
    alert(option.title);
}
}

HTML:

<div ng-app="myApp">

<div ng-controller="MyCtrl">
    <select ng-model="opt" ng-options="font.title for font in fonts" ng-change="change(opt)">
    </select>

    <p>{{opt}}</p>
</div>

</div>

1 Answer 1

3

Your module definition is incorrect, you need to supply a list of dependencies to init it correctly or an empty [] if you have none.

e.g.

var myApp = angular.module("myApp", []);

You are also missing a trailing ) when you register your controller.

var myApp = angular.module("myApp", []);

myApp.controller("MyCtrl", function($scope) {

    $scope.fonts = [
        {title: "Arial" , text: 'Url for Arial' },
        {title: "Helvetica" , text: 'Url for Helvetica' }
    ];
    $scope.change= function(option){
        alert(option.title);
    };
});

Fixed fiddle

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

3 Comments

Thanks, sometimes i´m really blind ;)
Just in addition: Why is this not working? I only added a parent controller: jsfiddle.net/w8LrL8xr/7
You are missing the closing ) for the other controller. :)

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.