solick
solick

Reputation: 2375

AngularJS select directive not working in jsfiddle

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>

Upvotes: 0

Views: 115

Answers (1)

Mark Coleman
Mark Coleman

Reputation: 40863

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

Upvotes: 3

Related Questions