使用AngularJS 1.3.15
jsFiddle:http://jsfiddle.net/leongaban/2g8vwmzo/
未能实例化模块myApp,原因是:错误:[$injector:nomod]http://errors.angularjs.org/1.3.15/$injector/nomod?p0=myApp错误(本机)在https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular.min.js:6:417在
(function() {
'use strict';
var app = angular
.module('myApp', ['MyCtrl'])
.controller('MyCtrl', Controller);
Controller.$inject = ['$scope'];
function Controller($scope) {
var vm = this;
var vs = $scope;
activate();
////////////////////////////////////////////////////////////////
function activate() {
vs.name = "stackoverflow";
vs.fonts = [
{title: "Arial" , text: 'Arial rules!' },
{title: "Helvetica" , text: 'Helvetica is hot!' }
];
vs.change= function(option){
alert(option.title);
}
}
}
})();
标记:
<div ng-app="myApp" ng-controller="MyCtrl">
<h1>{{name}}</h1>
<select ng-model="opt"
ng-change="change(font)">
<option ng-repeat="font in fonts" value="{{font.title}}">
{{font.title}}
</option>
</select>
<p>{{opt}}</p>
</div>
更改此
.module('myApp', ['MyCtrl'])
至
.module('myApp', [])
你可以走了!
模块函数中的第二个参数是模块依赖项的数组,这些模块是myApp
模块所依赖的其他模块。MyCtrl
是控制器而非模块。
更新:更改小提琴设置。将第二个下拉菜单设置为no wrap in body
看到它在这里运行http://jsfiddle.net/0h4cs2tp/