2017-08-06 40 views
0

我使用的是angularjs 1.65版本 ,它似乎$ sce讓我不明確 我一直在嘗試使用時間來修復它超過3小時。

這裏是模塊:

var app = angular.module('myApp', ['ui.router','ngclipboard','oitozero.ngSweetAlert']); 
app.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {}) 

這裏是控制器:

app.controller('monitormainController', 
['$rootScope','$scope','$timeout','SweetAlert','$sce', function 
($scope,$timeout,$rootScope,$watch,SweetAlert,$sce) { 

    $scope.copyset = function(name){ $scope.trustedHtml = 
    $sce.trustAsHtml(name); }; 

}); 

我得到它說$ SCE未定義

Failed to load resource: the server responded with a status of 404 (File not found) angular.js:14642 TypeError: Cannot read property 'trustAsHtml' of undefined at Scope.$scope.copyset (monitormainController.js:93) at fn (eval at compile (angular.js:15500), :4:153) at callback (angular.js:27285) at Scope.$eval (angular.js:18372) at Scope.$apply (angular.js:18472) at HTMLButtonElement. (angular.js:27290) at HTMLButtonElement.dispatch (jquery.js:5095) at HTMLButtonElement.elemData.handle (jquery.js:4766)

會很高興的錯誤得到任何答案非常感謝你!

回答

2

您的依賴關係在這裏的順序錯誤。您必須將數組中依賴關係的順序與函數中的參數完全匹配。此外,您期望在您的函數中使用$watch,但不會將其包含在依賴項列表中。

編輯:如果您打算使用$scope.$watch,而不是您創建或安裝$watch服務,這是不是一種可注射的服務。因此,它不應該作爲函數參數傳遞。

相反的:

['$rootScope','$scope','$timeout','SweetAlert','$sce', function 
($scope,$timeout,$rootScope,$watch,SweetAlert,$sce) { 

嘗試:。

['$rootScope','$scope','$timeout','SweetAlert','$sce', function 
($rootScope,$scope, $timeout, SweetAlert, $sce) { 
+0

仍然沒有工作:(,改變你的方式 同類有線IDK的怎麼說,甚至, 一切似乎 –

+0

當你安裝示波器的時候,angularjs給你$ watch。從我讀到的內容中獲得。 –

+0

我更新了答案;很可能你期望使用'$ scope。$ watch'而不是某些'$ watch'服務。remov應該讓與它有關的任何錯誤消失。 – Claies