如何在Angularjs中显示烤面包机信息?

时间:2022-05-19 11:49:57

Hello I am developing Angularjs Application. I am trying to display Toaster messages in my angular controller. I refereed http://angular-js.in/angular-toastr/. I am facing below issue. I am not able to call success,info etc notification from controller and i am getting annot read property 'success' of undefined error. I have tried as below.

您好我正在开发Angularjs应用程序。我试图在我的角度控制器中显示Toaster消息。我对http://angular-js.in/angular-toastr/进行了评价。我面临下面的问题。我无法从控制器调用成功,信息等通知,我得到了未定义错误的无法读取属性“成功”。我试过如下。

In index.html i have added below code.

在index.html中,我添加了以下代码。

<!--Toaster-->
    <script src="https://unpkg.com/angular-toastr/dist/angular-toastr.tpls.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/angular-toastr/dist/angular-toastr.css" />
    <!--Toaster-->  

this is my main.js

这是我的main.js

var app = angular.module('RoslpApp', ['pascalprecht.translate', 'ui.router', 'toastr']);
app.config(function ($stateProvider, $urlRouterProvider, $urlRouterProvider, $translateProvider, $translatePartialLoaderProvider) {
 //ui-routing states here});

app.controller('RoslpAppController', ['$scope', '$translate', function ($scope, $translate, toastr) {
    toastr.success('Hello world!', 'Toastr fun!');
    $scope.clickHandler = function (key) {

        $translate.use(key);
    };
}]);

May I know why I am facing issues here? any help would be appreciated. thank you

我可以知道为什么我在这里遇到问题吗?任何帮助,将不胜感激。谢谢

3 个解决方案

#1


2  

add toastr as string dependency to the controller.

将toastr添加为控制器的字符串依赖项。

change this

改变这一点

app.controller('RoslpAppController', ['$scope', '$translate',function ($scope, $translate, toastr) {

to this

对此

app.controller('RoslpAppController', ['$scope', '$translate','toastr',function ($scope, $translate, toastr) {

#2


2  

You are missing toastr in controller definition.

您在控制器定义中缺少toastr。

app.controller('RoslpAppController', ['$scope', '$translate','toastr', function ($scope, $translate, toastr) {

#3


2  

Try this

尝试这个

<html>
<head>
	<script Src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.js"></script>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
	<script src="http://cdnjs.cloudflare.com/ajax/libs/toastr.js/1.3.1/js/toastr.js"></script>
	<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/1.3.1/css/toastr.css">

	<script>
		var app=angular.module("myapp", []);
		app.controller("namesctrl", function($scope){

			$(function () {
				$('#error').click(function () {
        // make it not dissappear
        toastr.error("Noooo oo oo ooooo!!!", "Title", {
        	"timeOut": "0",
        	"extendedTImeout": "0"
        });
    });
				$('#info').click(function () {
   		// title is optional
   		toastr.info("Info Message", "Title");
   	});
				$('#warning').click(function () {
					toastr.warning("Warning");
				});
				$('#success').click(function () {
					toastr.success("YYEESSSSSSS");
				});
			});


		});

		
	</script>
</head>
<body ng-app="myapp" ng-controller="namesctrl">
	<input type="button" value="Error" id="error" />
	<input type="button" value="Info" id="info" />
	<input type="button" value="Warning" id="warning" />
	<input type="button" value="Success" id="success" />
	<br><br><br><br>
	See official example: <a href='http://codeseven.github.io/toastr/demo.html' target='blank'>Here</a>
</body>
</html>

#1


2  

add toastr as string dependency to the controller.

将toastr添加为控制器的字符串依赖项。

change this

改变这一点

app.controller('RoslpAppController', ['$scope', '$translate',function ($scope, $translate, toastr) {

to this

对此

app.controller('RoslpAppController', ['$scope', '$translate','toastr',function ($scope, $translate, toastr) {

#2


2  

You are missing toastr in controller definition.

您在控制器定义中缺少toastr。

app.controller('RoslpAppController', ['$scope', '$translate','toastr', function ($scope, $translate, toastr) {

#3


2  

Try this

尝试这个

<html>
<head>
	<script Src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.js"></script>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
	<script src="http://cdnjs.cloudflare.com/ajax/libs/toastr.js/1.3.1/js/toastr.js"></script>
	<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/1.3.1/css/toastr.css">

	<script>
		var app=angular.module("myapp", []);
		app.controller("namesctrl", function($scope){

			$(function () {
				$('#error').click(function () {
        // make it not dissappear
        toastr.error("Noooo oo oo ooooo!!!", "Title", {
        	"timeOut": "0",
        	"extendedTImeout": "0"
        });
    });
				$('#info').click(function () {
   		// title is optional
   		toastr.info("Info Message", "Title");
   	});
				$('#warning').click(function () {
					toastr.warning("Warning");
				});
				$('#success').click(function () {
					toastr.success("YYEESSSSSSS");
				});
			});


		});

		
	</script>
</head>
<body ng-app="myapp" ng-controller="namesctrl">
	<input type="button" value="Error" id="error" />
	<input type="button" value="Info" id="info" />
	<input type="button" value="Warning" id="warning" />
	<input type="button" value="Success" id="success" />
	<br><br><br><br>
	See official example: <a href='http://codeseven.github.io/toastr/demo.html' target='blank'>Here</a>
</body>
</html>