javascript jsFiddle 中带有模块和控制器的简单 AngularJS 示例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21417779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Simple AngularJS example with a module and controller in jsFiddle
提问by skube
This probably a combo jsFiddle/Angular question, but I'm trying to learn me some basic Angular and I'm not sure why it only works when I include the controller JS in the HTML pane. jsFiddle here
这可能是一个 jsFiddle/Angular 组合问题,但我正在尝试学习一些基本的 Angular,我不确定为什么它只在我将控制器 JS 包含在 HTML 窗格中时才有效。 jsFiddle在这里
Basically the following works:
基本上有以下工作:
<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>
But if I try to move the JS within the script tag to the JavaScript pane, it fails.
但是,如果我尝试将脚本标记中的 JS 移动到 JavaScript 窗格,则会失败。
回答by dimirc
Take a look at this articlefor some info about jsFiddle with Angular
看看这篇文章,了解有关 jsFiddle 和 Angular 的一些信息
Also more examples on AngularJS Wiki that you could use: https://github.com/angular/angular.js/wiki/JsFiddle-Examples
还有更多关于 AngularJS Wiki 的例子,你可以使用:https: //github.com/angular/angular.js/wiki/JsFiddle-Examples