javascript - jsFiddle 中带有模块和 Controller 的简单 AngularJS 示例

标签 javascript angularjs jsfiddle

这可能是一个 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/

相关文章:

javascript - 如何等待所有数据下载到Firebase(Firestore)存储中?

javascript - angular 1.5 组件,ui-router 解析,$onChanges 生命周期 Hook

javascript - AngularJS 代码中没有发生继承

javascript - 使用 Ember 动态添加和推送其他对象

javascript - 主干 - View 未渲染

javascript - 定义数据复选框数据表时列间距不正确

javascript - 使用 JavaScript 将字符串中的元音替换为其在字符串中的索引

javascript - ng-repeat 渲染并自动滚动到底部

Highcharts 基本条形图。如何从酒吧中删除中风

javascript - 将汉堡菜单和搜索框添加到导航菜单