[英]How to call function from module and show record in view file using MEAN stack?
I am working in MEAN stack and I using the controller and module file. 我正在MEAN堆栈中工作,并且正在使用控制器和模块文件。
module.js module.js
var app = angular.module("myApp", ['ngRoute', 'ngStorage']);
app.config(function($routeProvider) {
$routeProvider.
when('/allusers', {
controller: 'usercontroller',
templateUrl: 'js/view/allusers.html'
});
});
Now I want to call a usercontroller
function. 现在,我想调用一个usercontroller
函数。 How can I call function which is defined into the controller? 如何调用控制器中定义的功能?
My controller.js file is 我的controller.js文件是
app.controller("usercontroller", function($scope, $http, $localStorage, $location) {
$scope.allusers = function() {
$http({
method: 'POST',
url: '/api/addseat',
data: { email: 'shahjad.ahmad89@gmail.com', password: 123456 }
}).then(function successCallback(response) {
if (response.data.error) {
alert("Invalid email pasword");
} else {
$scope.dp = response.data;
$localStorage.pp = $scope.dp;
}
}, function errorCallback(response) {
alert("Invalid email pasword");
});
}
});
How to call the allusers
function from the module and how to display the record into view file? 如何从模块调用allusers
函数以及如何将记录显示到视图文件中?
You can call the allusers
function inside your controller by default when your controller loads as 默认情况下,当控制器加载allusers
可以在控制器内部调用allusers
函数。
$scope.allusers();
You can also call it through any button click or other event using ng-click
attribute. 您还可以使用ng-click
属性通过任何按钮单击或其他事件来调用它。
<input type="button" value="Submit" ng-click="allusers()"/>
And display the value as, 并将其显示为
For single value, <div>{{dp}}</div>
对于单个值, <div>{{dp}}</div>
For multiple values use ng-repeat
, 对于多个值,请使用ng-repeat
,
<div ng-repeat="d in dp">{{d}}</div>
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.