AngularJS控制器没有在jsFiddle中执行

时间:2015-11-28 18:22:00

标签: javascript angularjs jsfiddle

我正在尝试学习AngularJS中控制器和模块的最基本实现。

Here is the code I have tried:

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.firstName= "John";
    $scope.lastName= "Doe";
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<h1>
    This is the most <a href='http://www.w3schools.com/angular/tryit.asp?filename=try_ng_intro_controller'>basic angularJS controller</a> implementation
    </h1>
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{ firstName + " " + lastName }}

</div>

输出未更新:

output

2 个答案:

答案 0 :(得分:2)

您需要在框架和扩展程序标签的下拉菜单中选择No wrap - in <body>,查看图片:

enter image description here

更新了JSFiddle

答案 1 :(得分:1)

只是一个小问题,

Angularjs脚本未被引用。只需更改它就可以将其包裹在头部,

这是工作JsFiddle