简体   繁体   English

JSFiddle不运行我的AngularJS代码

[英]JSFiddle does not run my AngularJS code

After typing inside textarea and clicking on a button , I want to remove text inside textarea using AngularJS . textarea键入并单击button ,我想使用AngularJS删除textarea Please refer to following fiddle: 请参考以下小提琴:

http://jsfiddle.net/aman2690/2Ljrp54q/10/ http://jsfiddle.net/aman2690/2Ljrp54q/10/

Still getting 还在

Error: [$injector:modulerr] Failed to instantiate module MyApp due to:
[$injector:nomod] Module 'MyApp' is not available!

Even after setting ng-model to '' , textarea does not clean up. 即使将ng-model设置为''textarea也不会清理。

Your logic is fine. 你的逻辑很好。 Your JSFiddle isn't. 你的JSFiddle不是。 Set the framework options to No Wrap - in <head> . 将框架选项设置为No Wrap - in <head>

You need to change your plunker No wrap - in <body> and add <body ng-app="MyApp"> to Fiddle Options . 您需要更改您的plunker No wrap - in <body>并将<body ng-app="MyApp">Fiddle Options

Here is an example: jsfiddle 这是一个例子: jsfiddle

need to use $scope in controller $scope acts as a model. 需要在控制器$ scope中使用$ scope作为模型。 Check the link below 检查以下链接

http://plnkr.co/edit/TpGfbDOtxvrC6FwhpbT8?p=preview http://plnkr.co/edit/TpGfbDOtxvrC6FwhpbT8?p=preview

 var app = angular.module('MyApp', []); app.controller('MainCtrl', function ($scope) { $scope.message = ''; $scope.clicked = function () { console.log("here"); $scope.message = ''; }; }); 

将JSFiddle的代码复制并粘贴到本地HTML文件中,因为JSFiddle提供了控制台错误,代码按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM