-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
83 lines (76 loc) · 3.14 KB
/
app.js
File metadata and controls
83 lines (76 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var app = angular.module("myApp", ['ui.bootstrap', 'pascalprecht.translate']);
app.factory("myFactory", function() {
var datas = {};
var dataArray = [];
var tId = '';
var tName = '';
datas.setData = function(id, name) {
tId = id;
tName = name;
dataArray.push({
'taskid': tId,
'taskname': tName
});
}
datas.getData = function() {
return dataArray;
}
return datas;
});
app.config(function($translateProvider, $translatePartialLoaderProvider) {
$translatePartialLoaderProvider.addPart('home');
$translateProvider.useLoader('$translatePartialLoader', {
urlTemplate: '/i18n/{part}/{lang}.json'
});
});
app.controller("myController", ['$scope', '$uibModal', 'myFactory', '$translatePartialLoader', '$translate', function($scope, $uibModal, myFactory, $translatePartialLoader, $translate) {
$translate.use('en');
$scope.data = myFactory.getData();
$scope.text="hai";
$scope.setLang = function(val) {
$translate.use(val);
}
$scope.add_item = function() {
var modalInstance = $uibModal.open({
templateUrl: 'popup.html',
controller: 'popController',
});
}
$scope.remove = function(id) {
angular.forEach($scope.data, function(value, key) {
angular.forEach(value, function(val, index) {
if (id === val) {
$scope.data.splice(key, 1);
}
})
});
}
}]);
app.controller('popController', ['$scope', 'myFactory','$uibModalInstance', function($scope, myFactory,$uibModalInstance) {
$scope.hideTask = function() {
$uibModalInstance.dismiss('cancel');
};
$scope.id_valid = /^[0-9]+$/;
$scope.name_valid = /^[a-zA-Z0-9]+$/;
$scope.flag = 0;
$scope.addTask = function() {
if ($scope.new_taskid && $scope.new_taskname) {
angular.forEach($scope.data, function(value, key) {
angular.forEach(value, function(val, index) {
if ($scope.new_taskid == val) {
alert("already exist");
$scope.flag = 1;
}
})
})
if ($scope.flag == 0) {
myFactory.setData($scope.new_taskid, $scope.new_taskname);
$scope.taskk = myFactory.getData();
console.log($scope.taskk);
$scope.hideTask();
}
} else {
alert("Enter numbers");
}
}
}]);