簡體   English   中英

在jsFiddle中使用模塊和控制器的簡單AngularJS示例

[英]Simple AngularJS example with a module and controller in jsFiddle

這可能是一個組合jsFiddle / Angular問題,但我正在嘗試向我學習一些基本的Angular,我不確定為什么它只在我在HTML窗格中包含控制器JS時才有效。 jsFiddle在這里

基本上以下工作:

<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窗格,則會失敗。

有關jsFiddle與Angular的一些信息,請查看本文

您還可以使用AngularJS Wiki上的更多示例: https//github.com/angular/angular.js/wiki/JsFiddle-Examples

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM