gpt4 book ai didi

c# - 将 angularJs 范围内容传递给 javascript 变量

转载 作者:行者123 更新时间:2023-12-03 12:04:53 25 4
gpt4 key购买 nike

我正在尝试将 AngularJS $scope 变量 htmlContent 保存到 JavaScript 变量 test 中,以便我可以将数据发送到 C# Controller 方法。但是它不起作用。我究竟做错了什么?

<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>

最佳答案

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>

关于c# - 将 angularJs 范围内容传递给 javascript 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25230249/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com