0

I'm trying to save an AngularJS $scope variable, htmlContent, into a JavaScript variable, test, so I can send the data to a c# controller method. However it is not working. What am I doing wrong?

<script type="text/javascript">
 angular.module("textAngularTest", ['textAngular']);
 function wysiwygeditor($scope) {
 $scope.orightml = '<h2>New Note...</h2>';
 $scope.htmlcontent = $scope.orightml;
 $scope.disabled = false;
 //I'm not getting any data passed to the "test" variable
 var test = $scope.htmlcontent;
 $("#newnote").click(function () {
 $.post("/Home/SaveWNote", { jsonData: test });
 });
 };
 </script>
asked Aug 10, 2014 at 15:44
3
  • Why use Jquery if you have Angular... It's the "anti-pattern" of Angular. Jquery may be use only if there's no possibility with Angular services/directives etc. Commented Aug 10, 2014 at 17:03
  • Ok. I'm a newbie on angular. What is the correct way to send the data $scope.htmlcontent to a ActionResult in my controller? Commented Aug 10, 2014 at 17:17
  • What is the explicit error you got? Commented Aug 10, 2014 at 17:17

1 Answer 1

1

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

JS:

var app = angular.module('myApp', ['textAngular']);
app.controller('AppCtrl', function($scope, $http) {
 $scope.htmlcontent = "<h2>New Note...</h2>";
 $scope.save =function() {
 console.log( $scope.htmlcontent );
 $http.post("/Home/SaveWNote", { jsonData: $scope.htmlcontent });
 }
});

HTML:

<!doctype html>
<head>
 <meta charset="utf-8">
 <title>Testing</title>
 <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
 <link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css">
 <script src="https://cdnjs.cloudflare.com/ajax/libs/rangy/1.2.3/rangy-core.js"></script>
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
 <script src='http://cdnjs.cloudflare.com/ajax/libs/textAngular/1.2.0/textAngular-sanitize.min.js'></script>
 <script src='http://cdnjs.cloudflare.com/ajax/libs/textAngular/1.2.0/textAngular.min.js'></script>
 <script src="script.js"></script>
 <link rel="stylesheet" href="style.css"/>
</head>
<body ng-app="myApp">
 <div ng-controller="AppCtrl">
 <div text-angular ng-model="htmlcontent "></div>
 <button ng-click="save()">Save</button>
 <br/>
 Your htmlcontent <pre>{{htmlcontent}}</pre>
 </div>
</body>
</html>
answered Aug 10, 2014 at 17:33
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.