Angularjs 如何从角度控制器调用JavaScript函数?
如何从角度控制器调用Angularjs 如何从角度控制器调用JavaScript函数?,angularjs,angularjs-scope,Angularjs,Angularjs Scope,如何从角度控制器调用showNotification()JS函数?这是因为我使用的插件只包含JS文件中的代码 authentication.controller('loginController', function($scope , $http ) { $http({ method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=
showNotification()
JS函数?这是因为我使用的插件只包含JS文件中的代码
authentication.controller('loginController', function($scope , $http ) {
$http({
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
data: $.param(($scope.loginData)),
}).success(function(data, status, headers, config)
{
if(data.status == "success"){
}
else
{
alert("invalid credentials");
showNotification(){
message: "This is Auto Close notification. Message will close after 2 seconds",
autoClose: true,
duration: 2
} //THIS IS JS FUNCTION
}
}).
error(function(data, status, headers, config) {
console.log("Login failed");
showNotification(){
message: "This is Auto Close notification. Message will close after 2 seconds",
autoClose: true,
duration: 2
} //THIS IS JS FUNCTION
});
});
我的JS函数在单独的JS文件中
function showNotification(params){
// Function Logic
}
只需包含插件的javascript文件,就可以了 为了正确使用,最好用angularJS服务或指令包装插件。请看演示 您只需确保在使用controller加载文件之前加载了带有js函数的文件
var app = angular.module('app', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.show = function() {
showNotification("Hello from Angular")
}
});
。。。。其他js文件中的函数:
function showNotification(message){
alert(message)
}
请给我解释一下。我已经添加了我的示例,但是我得到了一个错误,你在angular文件之前附加了外部js文件吗?当然是的。我已经包括了包含shownotification()functionPart的JS文件,我不理解对函数的调用!你把参数放在身体里看看