这可能是一个 jsFiddle/Angular 组合问题,但我正在尝试学习一些基本的 Angular,但我不确定为什么只有当我在 HTML Pane 中包含 Controller JS 时它才有效。 jsFiddle here
基本上有以下工作:
<div ng-app="myAppModule" ng-controller="someController">
<!-- Show the name in the browser -->
<h1>Welcome {{ name }}</h1>
<p>made by : {{userName}}</p>
<!-- Bind the input to the name -->
<input ng-model="name" name="name" placeholder="Enter your name" />
</div>
<script>
var myApp = angular.module('myAppModule', []);
myApp.controller('someController', function($scope) {
// do some stuff here
$scope.userName = "skube";
});
</script>
但是,如果我尝试将脚本标记内的 JS 移动到 JavaScript Pane ,则会失败。
最佳答案
看看this article有关 jsFiddle 与 Angular 的一些信息
您还可以使用 AngularJS Wiki 上的更多示例: https://github.com/angular/angular.js/wiki/JsFiddle-Examples
关于javascript - jsFiddle 中带有模块和 Controller 的简单 AngularJS 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21417779/