简体   繁体   English

用angularJS绑定applet参数

[英]Binding applet parameters with angularJS

I need to pass a dynamic param to an applet. 我需要将动态参数传递给applet。

This is my controller: 这是我的控制器:

'use strict';

    angular.module('jworkApp')
      .controller('AppletCtrl',['$scope', function (scope) {
              scope.base64 = "abcd";
}]);

This is my view, the parameter base64 is defined in the controller as "abcd" 这是我的观点,参数base64在控制器中定义为“ abcd”

<p>{{base64}}</p>
<APPLET>
  <PARAM name="text" value={{base64}} />
</APPLET>

When I run my page I see in the p tag the string 'abcd' , but the applet param's value it's simply "{{base64}}". 当我运行页面时,我在p标签中看到字符串'abcd',但是applet参数的值只是“ {{base64}}”。

How could i fix it? 我该如何解决?

I solved passing the entire applet declaration. 我解决了传递整个applet声明的问题。 In this way it works correctly. 这样,它可以正常工作。

Controller: 控制器:

angular.module('jworkApp')
  .controller('AppletCtrl',['$scope', '$sce', function ($scope, $sce) {

            $scope.b64 = 'AAAA';
            $scope.applet = 
                "<APPLET>"+
                "<PARAM name=\"testo\" VALUE=\""+$scope.b64+"\" />"+
                "</APPLET>";

             $scope.getAppletCode = function() {
                  return $sce.trustAsHtml($scope.applet);
             };

  }]);

view: 视图:

<div ng-bind-html="getAppletCode()"></div>

A working example might be: 一个有效的示例可能是:

<!doctype html>
<html ng-app = "app">
<head>
    <script src = "angular.min.js"> </script>
</head>

<div ng-controller = "Ctrl">
    <p>{{base64}}</p>
    <APPLET>
      <PARAM id = "applet"name="{{base64}}" value="{{base64}}" />
    </APPLET>

    <div id = "debug">

    </div>
</div>

<script>
    var app = angular.module('app', []);
    app.controller('Ctrl', ['$scope', function($scope) {
        $scope.base64 = "base-sixty-four";
    }]);


    //Code to prove, that indeed, the value is what you're looking for     
    var applet = document.getElementById('applet');
    document.getElementById('debug').innerHTML = applet.value;
</script>
</html>

One thing to note: since you can't see the changes on the webpage, the way to view the result is through some kind of Development Tools, such as Chrome Dev Tools, because the value has been changed by angular after the page has been loaded. 需要注意的一件事:由于您无法在网页上看到更改,因此查看结果的方法是通过某种开发工具(例如Chrome Dev Tools)进行,因为在更改页面后,该值已按角度进行了更改加载。 This means, that simply viewing the source will not show desired results. 这意味着,仅查看源将不会显示期望的结果。

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

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