如何让 <script> 共享数据给 Angular 控制器?

How to get <script> to share data to Angular Controller?

我将 ASP.NET(aspx 网络表单)与 C# 和 AngularJS 一起使用。我的 index.html 文件中有一些脚本:

<script>
    function get_stuff(){
       var stuff = document.getElementById("stuff_here").value;
       console.log(stuff);
       // output: [{"name":"toy duck", "color":"yellow"},{"name":"flute", "color":"white"}]
    }
</script>
<input type='hidden' id='stuff_here' value='...' />
<button onclick="get_stuff()">RUN</button>

输出符合要求。但是,我希望能够访问我的 Angular 控制器的输出,例如在按钮上使用 ng-click 并让 angular 函数执行相同的操作。不幸的是,按下按钮时 ng-click 不起作用。我也试过将 var 东西作为函数外的全局变量,但我的 Angular 函数也无法获取它。

如何获取对象??在此先感谢您的帮助!

您可以将引导的应用程序数据保存为 Angular 服务,或者更准确地说,保存为 Angular 提供程序。

<script>
    var stuff = document.getElementById("stuff_here").value;
    angular.module("myApp").value("myProviderStuff", stuff);
</script>

然后在您的 angular 应用中,

var module = angular.module("myApp");
module.controller("SomeController", function($scope, myProviderStuff) {
$scope.stuff = myProviderStuff;