私はAngularJSでの解決に苦労しています。私は、カスタムコンポーネントをロードし、その関数を呼び出すが、方法を見つけられなかった。解決方法から関数を呼び出すには?
以下のコードでは、アイテムが正常に投稿されたらSweetAlert(http://t4t5.github.io/sweetalert/)を表示しようとしました。
機能config($ stateProvider、$ urlRouterProvider、$ ocLazyLoadProvider){ $ urlRouterProvider.otherwise( "/ index/main");
$ocLazyLoadProvider.config({
// Set to true if you want to see what and when is dynamically loaded
debug: false
});
$stateProvider
....
.state('index.item', {
url: "/:itemId/edit",
templateUrl: "views/item-edit.html",
data: {pageTitle: 'Edit Item'},
controller: function ($scope, $http, $stateParams, $rootScope, $state, $modal, $log, $ocLazyLoad) {
//console.log($routeParams.itemId);
var demo1 = function() {
SweetAlert.swal({
title: "Welcome in Alerts",
text: "Lorem Ipsum is simply dummied text of the printing and typesetting industry."
});
}
$scope.updateItem = function() {
$log.log('Submiting item info');
$http.post('/api/item', $scope.item)
.success(function(data) {
demo1();
})
.error(function(data) {
console.log('Error: ' + data);
});
}
},
resolve: {
loadPlugin: function ($ocLazyLoad) {
return $ocLazyLoad.load([
{
files: ['js/plugins/sweetalert/sweetalert.min.js', 'css/plugins/sweetalert/sweetalert.css']
},
{
name: 'oitozero.ngSweetAlert',
files: ['js/plugins/sweetalert/angular-sweetalert.min.js']
}
]);
}
}
})
上記のコードを使用しようとしますが、私は次のエラーを取得:
ReferenceError: SweetAlert is not defined
at demo1 (config.js:156)
at config.js:170
at angular.js:9354
at angular.js:13168
at l.$eval (angular.js:14381)
at l.$digest (angular.js:14197)
at l.$apply (angular.js:14486)
at l (angular.js:9644)
at O (angular.js:9834)
at XMLHttpRequest.w.onload (angular.js:9775)
をし、主な理由は、おそらく、コントローラ内の任意の場所と呼ばれていないプロパティloadPluginです。誰も定義されたプラグインをロードしてコントローラ内で使用するためにコードを変更する方法を知っていますか?
ありがとうございます!
私はそれを見ることができます。私が知らないのは、SweetAlertの定義を含むファイルを読み込む方法です。 –
@NikoGamulinが例を追加しました。 –