admin管理员组文章数量:1331849
This probably a bo 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
Basically the following works:
<div ng-app="myAppModule" ng-controller="someController">
<!-- Show the name in the browser -->
<h1>Wele {{ 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.
This probably a bo 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
Basically the following works:
<div ng-app="myAppModule" ng-controller="someController">
<!-- Show the name in the browser -->
<h1>Wele {{ 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.
Share Improve this question asked Jan 28, 2014 at 21:57 skubeskube 6,1859 gold badges57 silver badges82 bronze badges 3-
3
No wrap - in <head>
jsfiddle/E9bU5/3 – elclanrs Commented Jan 28, 2014 at 21:58 - I swear I tried that, but you're correct. What does "No wrap - in <head>" mean? It doesn't make sense to me – skube Commented Jan 28, 2014 at 22:00
-
2
jsFiddle wraps your code in a ready or load event by default, and Angular might not find what it needs in the global scope when piling your template at the time is needed.
No wrap in <head>
just loads the script in the head, without a wrap. – elclanrs Commented Jan 28, 2014 at 22:04
1 Answer
Reset to default 5Take a look at this article for some info about jsFiddle with Angular
Also more examples on AngularJS Wiki that you could use: https://github./angular/angular.js/wiki/JsFiddle-Examples
本文标签: javascriptSimple AngularJS example with a module and controller in jsFiddleStack Overflow
版权声明:本文标题:javascript - Simple AngularJS example with a module and controller in jsFiddle - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742226906a2436489.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论