Angular iframe dynamisch:$ sce:无法读取undefined的属性

时间:2014-07-24 11:45:17

标签: angularjs

我尝试为关键字制作一个单词组合子。合并后我想将动态谷歌搜索请求加载到iframe中。不幸的是我在$ sce-service上遇到了一些问题。

ERRORMESSAGE: TypeError: Cannot read property 'trustAsUrl' of undefined

Same error for $sce.trustAsResourceUrl(...);

我的傻瓜: http://plnkr.co/edit/N2nzBVElPtegaPYUCXlz

重要部分:

Controller.js

var keywordAppControllers = angular.module('keywordAppControllers', []);

keywordAppControllers.controller('KeywordCtrl', ['$scope','$sce',
  function ($scope) {
    $scope.myData = {};
    $scope.myData.previewUrl="";

    $scope.serpPreview = function(keyword, $sce, $scope) {
      previewUrl="https://www.google.de/search?q=" + encodeURIComponent(keyword);
      // previewUrl="https://www.google.de/search?q=" + keyword;
      console.log(previewUrl);
      trustedUrl = $sce.trustAsUrl('https://www.google.de/');
      console.log(trustedUrl);
      // $scope.myData.previewUrl = $sce.trustAsUrl('www.google.de/');
      // $scope.myData.previewUrl = $sce.trustAsUrl('https://www.google.de/');
      // $scope.myData.previewUrl = $sce.trustAsUrl('https://google.de/');
      // $scope.myData.previewUrl = $sce.trustAsUrl('//google.de/');
    };
    // create a blank object to hold our form information
    // $scope will allow this to pass between controller and view
    $scope.formData = {};
  }
]);

App.js:

var keywordApp = angular.module('keywordApp', [
  'keywordAppControllers'
]).config(function($sceDelegateProvider) {
   $sceDelegateProvider.resourceUrlWhitelist([
     // Allow same origin resource loads.
     'self',
     // Allow loading from our assets domain.  Notice the difference between * and **.
     'https://google.de/*',
     'http://google.de/*',
     'https://google.de/**',
     'http://google.de/**'
   ]);
 });

0 个答案:

没有答案