var myApp = angular.module('produceline', []);
myApp.factory('ajax', ["$http", "$q", "$log", function ($http, $q, $log) {
return {
//post请求,第一个参数是URL,第二个参数是向服务器发送的参数(JSON对象),
post: function (url, data, funsuccess) {
var deferred = $q.defer();
var tempPromise;
if (data != null && data != undefined && data != "") {
tempPromise = $http.post(url, data);
} else {
tempPromise = $http.post(url);
}
tempPromise.success(function (data, header, config, status) {
deferred.resolve(data);
}).error(function (msg, code) {
$log.error(msg, "post url:" + url + " 出错,代码:" + code);
deferred.reject(msg);
});
return deferred.promise.then(funsuccess);
},
//get请求,第一个参数是URL,第二个参数是向服务器发送的参数(JSON对象), 此方法有问题
get: function (url, data, funsuccess) {
var deferred = $q.defer();
var tempPromise;
//判断用户是否传递了参数,如果有参数需要传递参数
if (data != null && data != undefined && data != "") {
tempPromise = $http.get(url, data); //params {params: {id:5}}
} else {
tempPromise = $http.get(url);
}
tempPromise.success(function (data, header, config, status) {
deferred.resolve(data);
}).error(function (msg, code) {
deferred.reject(msg);
$log.error(msg, "get Url:" + url + " 出错,代码:" + code);
});
return deferred.promise.then(funsuccess);
}
};
}]);
myApp.controller('producelineController', ['$scope', "ajax", function ($scope, ajax) {
//扫描枪中止符 13 为回车
$scope.endWidthScan = 13; $scope.model = {}; $scope.partSegments = []; //生产线分段 $scope.init = function () {
$("#scantxt").focus();
$.extend($scope.model, modeljson);
$scope.partSegments = partSegments || [];
//for (var i = 0; i < $scope.partSegments.length; i++) {
// $scope.partcodesmodel[$scope.partcodes[i]] = '';
//}
}; $scope.init(); $scope.SaveSacnedProduct = function (product) {
//一次保存一个扫描项
var data = {};
data[product] = $scope.ScanedHash[product];
ajax.post($scope.model.UrlLineSave, { 'id': $scope.model.ID, 'json': angular.toJson(data) }, function (response) {
console.log('get ' + $scope.model.UrlLineSave + ' return t:' + response.t);
})
}; $scope.newSegment = function () {
var seg = { SegmentName: '', SegmentCode: '', Remark: '' };
$scope.partSegments.push(seg);
}; $scope.delSegment = function (idx,array) {
array.splice(idx, 1)
}; $scope.ProductScanComplete = function () {
$scope.CopyToHash($scope.ScaningProduct);
$scope.ScaningProduct = "";
$scope.complete.push($scope.ScaningProduct)
$scope.PlaySuccess(); } $scope.IsProductComplete = function (product) {
if (product == '' || product == null) {
return false;
}
for (var i = 0 ; i < $scope.partcodes.length ; i++) {
var t = $scope.partcodesmodel[$scope.partcodes[i]];
if (t && t != null && t != '') {
continue;
}
return false;
}
return true;
};
$scope.AllEmpty = function (product) {
for (var i = 0 ; i < $scope.partcodes.length ; i++) {
var t = $scope.partcodesmodel[$scope.partcodes[i]];
if (t == '') {
continue;
}
return false;
}
return true; }; $scope.showJson = function () { alert(angular.toJson(
{
//'complete': $scope.complete,
//'partcodes': $scope.complete,
//'partcodesmodel': $scope.partcodesmodel,
ScanedHash: $scope.ScanedHash,
ID: $scope.ID
//ScaningProduct: $scope.ScaningProduct,
//ScanedPartHash: $scope.ScanedPartHash,
//samecodecount: $scope.samecodecount
})
);
}; }]);

  

一个简易版的Angular js 三层 示例的更多相关文章

  1. 来,我们手写一个简易版的mock.js吧(模拟fetch && Ajax请求)

    预期的mock的使用方式 首先我们从使用的角度出发,思考编码过程 M1. 通过配置文件配置url和response M2. 自动检测环境为开发环境时启动Mock.js M3. mock代码能直接覆盖g ...

  2. 使用 js 和 Beacon API 实现一个简易版的前端埋点监控 npm 包

    使用 js 和 Beacon API 实现一个简易版的前端埋点监控 npm 包 前端监控,埋点,数据收集,性能监控 Beacon API https://caniuse.com/beacon 优点,请 ...

  3. 使用 js 实现一个简易版的模版引擎

    使用 js 实现一个简易版的模版引擎 regex (function test() { this.str = str; })( window.Test = ...; format() { let ar ...

  4. 使用 js 实现一个简易版的 drag & drop 库

    使用 js 实现一个简易版的 drag & drop 库 具有挑战性的前端面试题 H5 DnD js refs https://www.infoq.cn/article/0NUjpxGrqRX ...

  5. 使用 js 实现一个简易版的动画库

    使用 js 实现一个简易版的动画库 具有挑战性的前端面试题 animation css refs https://www.infoq.cn/article/0NUjpxGrqRX6Ss01BLLE x ...

  6. 使用 js 实现一个简易版的 GIPHY 动图搜索 web 应用程序

    使用 js 实现一个简易版的 GIPHY 动图搜索 web 应用程序 具有挑战性的前端面试题 API JAMstack refs https://www.infoq.cn/article/0NUjpx ...

  7. 使用 js 实现一个简易版的 async 库

    使用 js 实现一个简易版的 async 库 具有挑战性的前端面试题 series & parallel 串行,并行 refs https://www.infoq.cn/article/0NU ...

  8. 使用 js 实现一个简易版的 vue 框架

    使用 js 实现一个简易版的 vue 框架 具有挑战性的前端面试题 refs https://www.infoq.cn/article/0NUjpxGrqRX6Ss01BLLE xgqfrms 201 ...

  9. 手动实现一个简易版SpringMvc

    版权声明:本篇博客大部分代码引用于公众号:java团长,我只是在作者基础上稍微修改一些内容,内容仅供学习与参考 前言:目前mvc框架经过大浪淘沙,由最初的struts1到struts2,到目前的主流框 ...

随机推荐

  1. Threading and Tasks in Chrome

    Threading and Tasks in Chrome Contents Overview Threads Tasks Prefer Sequences to Threads Posting a ...

  2. Python多版本情况下四种快速进入交互式命令行的操作技巧

    因为工作需求或者学习需要等原因,部分小伙伴的电脑中同时安装了Python2和Python3,相信在Python多版本的切换中常常会遇到Python傻傻分不清楚的情况,今天小编整理了四个操作技巧,以帮助 ...

  3. javascript面向对象编程,带你认识封装、继承和多态

    原文链接:点我 周末的时候深入的了解了下javascript的面向对象编程思想,收获颇丰,感觉对面向对象编程有了那么一丢丢的了解了~很开森 什么是面向对象编程 先上一张图,可以对面向对象有一个大致的了 ...

  4. Codeforces 528A Glass Carving STL模拟

    题目链接:点击打开链接 题意: 给定n*m的矩阵.k个操作 2种操作: 1.H x 横向在x位置切一刀 2.V y 竖直在y位置切一刀 每次操作后输出最大的矩阵面积 思路: 由于行列是不相干的,所以仅 ...

  5. 理解Linq查询

    using System; using System.Linq; static class Program { static double Square(double n) { Console.Wri ...

  6. js --- 字符串和 二进制 互相转换

    //将字符串转换成二进制形式,中间用空格隔开 function strToBinary(str){ var result = []; var list = str.split("" ...

  7. POJ - 3847 Moving to Nuremberg 动归

    POJ - 3847 Moving to Nuremberg 题意:一张无向有权图,包括边权和点权,求一点,使得到其他点的点权*边权之和最小 思路: #pragma comment(linker, & ...

  8. Gym - 100625G Getting Through 计算几何+并查集

    http://codeforces.com/gym/100625/attachments/download/3213/2013-benelux-algorithm-programming-contes ...

  9. spring security oauth2 架构---官方

    原文地址:https://projects.spring.io/spring-security-oauth/docs/oauth2.html Introduction This is the user ...

  10. linux RAC 安装失败完全卸载

    1,删除软件安装目录 rm -rf /u01/app 2,删除以下目录内容 rm -rf /tmp/.oracle rm -rf   /tmp/* rm -rf   /tmp/ora* rm -rf ...