亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

javascript - Angular controlller控制域和原生js的關系

瀏覽:94日期:2024-03-08 15:12:36

問題描述

寫了一段js代碼,發現在controller里寫的原生js都不管用,報錯顯示無法找到該函數,代碼如下所示:

app.controller(’orderFormCtrl’, function ($scope, $http) { // 訂單備注 $scope.food_remarks = []; // 訂單詳情數組 $scope.forms_detail = []; $scope.food_detail = []; // 查詢訂單詳情 $scope.search_detail = function(index){ $scope.forms_detail = $scope.food_forms[index];$scope.food_remarks = $scope.food_forms[index].remarks;console.log($scope.forms_detail);// var form_num = $scope.forms_detail.order_number;$scope.food_detail = $scope.food_forms[index].food_detail;// console.log($scope.food_detail);for (var i = 0; i < $scope.food_detail.length; i++) { for (var j = 0; j < $scope.food_menu.length; j++) {if ($scope.food_detail[i].id == $scope.food_menu[j].id) { $scope.food_detail[i].name = $scope.food_menu[j].name; $scope.food_detail[i].price = $scope.food_menu[j].price; $scope.food_detail[i].img = $scope.food_menu[j].img;} }} }; //計算總價 $scope.allSum=function(){ var allPrice = 0; for(var i= 0;i<$scope.food_detail.length;i++){ allPrice+=$scope.food_detail[i].price*$scope.food_detail[i].num; // console.log(allPrice);} return allPrice; };var LODOP; //聲明為全局變量 function printPreview(){ //創建小票打印頁 CreatePrintPage(); //打印預覽 LODOP.PREVIEW(); } /** * 樣例函數,服務器確認訂單后執行 */ function printOrder() {//創建小票打印頁 CreatePrintPage(); //開始打印 LODOP.PRINT(); } function CreatePrintPage(json) { //json 創建模擬服務器響應的訂單信息對象 var json = {'title':'XXXXX訂單信息', 'name':'張三', 'phone': '138123456789', 'orderTime': '2012-10-11 15:30:15', 'orderNo': '20122157481315', 'shop':'XX連鎖', 'total':25.10,'totalCount':6, 'goodsList':[ {'name':'菜心(無公害食品)', 'price':5.00, 'count':2, 'total':10.08}, {'name':'菜心(無公害食品)', 'price':5.00, 'count':2, 'total':10.02}, {'name':'旺菜', 'price':4.50, 'count':1, 'total':4.50}, {'name':'黃心番薯(有機食品)', 'price':4.50, 'count':1, 'total':4.50} ] } var hPos=10,//小票上邊距 pageWidth=580,//小票寬度 rowHeight=15,//小票行距 //獲取控件對象 LODOP=getLodop(document.getElementById(’LODOP_OB’),document.getElementById(’LODOP_EM’)); //初始化 LODOP.PRINT_INIT('打印控件功能演示_Lodop功能_名片'); //添加小票標題文本 LODOP.ADD_PRINT_TEXT(hPos,30,pageWidth,rowHeight,json.title); //上邊距往下移 hPos+=rowHeight; LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,'姓名:'); LODOP.ADD_PRINT_TEXT(hPos,30,pageWidth,rowHeight,json.name); //hPos+=rowHeight; //電話不換行 LODOP.ADD_PRINT_TEXT(hPos,70,pageWidth,rowHeight,'電話:'); LODOP.ADD_PRINT_TEXT(hPos,100,pageWidth,rowHeight,json.phone); hPos+=rowHeight; LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,'下單時間:'); LODOP.ADD_PRINT_TEXT(hPos,60,pageWidth,rowHeight,json.orderTime); hPos+=rowHeight; LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,'訂單編號:'); LODOP.ADD_PRINT_TEXT(hPos,60,pageWidth,rowHeight,json.orderNo); hPos+=rowHeight; LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,'取貨門店:'); LODOP.ADD_PRINT_TEXT(hPos,60,pageWidth,rowHeight,json.shop); hPos+=rowHeight; LODOP.ADD_PRINT_LINE(hPos,2, hPos, pageWidth,2, 1); hPos+=5; LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,'商品名稱'); LODOP.ADD_PRINT_TEXT(hPos,70,pageWidth,rowHeight,'單價'); LODOP.ADD_PRINT_TEXT(hPos,110,pageWidth,rowHeight,'數量'); LODOP.ADD_PRINT_TEXT(hPos,140,pageWidth,rowHeight,'小計'); hPos+=rowHeight; //遍歷json的商品數組 for(var i=0;i<json.goodsList.length;i++){ if(json.goodsList[i].name.length<4){ LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,json.goodsList[i].name); }else { //商品名字過長,其他字段需要換行 LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,json.goodsList[i].name); hPos+=rowHeight; } LODOP.ADD_PRINT_TEXT(hPos,70,pageWidth,rowHeight,json.goodsList[i].price); LODOP.ADD_PRINT_TEXT(hPos,115,pageWidth,rowHeight,json.goodsList[i].count); LODOP.ADD_PRINT_TEXT(hPos,140,pageWidth,rowHeight,json.goodsList[i].total); hPos+=rowHeight; } //商品遍歷打印完畢,空一行 hPos+=rowHeight; //合計 LODOP.ADD_PRINT_TEXT(hPos,80,pageWidth,rowHeight,'合計:'+json.totalCount); LODOP.ADD_PRINT_TEXT(hPos,130,pageWidth,rowHeight,'¥'+json.total); hPos+=rowHeight; LODOP.ADD_PRINT_TEXT(hPos,2,pageWidth,rowHeight,(new Date()).toLocaleDateString()+' '+(new Date()).toLocaleTimeString()) hPos+=rowHeight; LODOP.ADD_PRINT_TEXT(hPos,25,pageWidth,rowHeight,'謝謝惠顧,歡迎下次光臨!'); //初始化打印頁的規格 LODOP.SET_PRINT_PAGESIZE(3,pageWidth,45,'XXXXX訂單信息');} });

后來發現如果把原生js放到controller的控制域外就可以找到該函數,并且可以正常運行(如下)

app.controller(’orderFormCtrl’, function ($scope, $http) { // 訂單備注 $scope.food_remarks = []; // 訂單詳情數組 $scope.forms_detail = []; $scope.food_detail = []; // 查詢訂單詳情 $scope.search_detail = function(index){ $scope.forms_detail = $scope.food_forms[index];$scope.food_remarks = $scope.food_forms[index].remarks;console.log($scope.forms_detail);// var form_num = $scope.forms_detail.order_number;$scope.food_detail = $scope.food_forms[index].food_detail;// console.log($scope.food_detail);for (var i = 0; i < $scope.food_detail.length; i++) { for (var j = 0; j < $scope.food_menu.length; j++) {if ($scope.food_detail[i].id == $scope.food_menu[j].id) { $scope.food_detail[i].name = $scope.food_menu[j].name; $scope.food_detail[i].price = $scope.food_menu[j].price; $scope.food_detail[i].img = $scope.food_menu[j].img;} }} }; //計算總價 $scope.allSum=function(){ var allPrice = 0; for(var i= 0;i<$scope.food_detail.length;i++){ allPrice+=$scope.food_detail[i].price*$scope.food_detail[i].num; // console.log(allPrice);} return allPrice; }; });//controller控制域外var LODOP; //聲明為全局變量 function printPreview(){ //創建小票打印頁 CreatePrintPage(); //打印預覽 LODOP.PREVIEW(); } /** * 樣例函數,服務器確認訂單后執行 */ function printOrder() {//創建小票打印頁 CreatePrintPage(); //開始打印 LODOP.PRINT(); } function CreatePrintPage(json) { //json 創建模擬服務器響應的訂單信息對象 var json = {'title':'XXXXX訂單信息', 'name':'張三', 'phone': '138123456789', 'orderTime': '2012-10-11 15:30:15', 'orderNo': '20122157481315', 'shop':'XX連鎖', 'total':25.10,'totalCount':6, 'goodsList':[ {'name':'菜心(無公害食品)', 'price':5.00, 'count':2, 'total':10.08}, {'name':'菜心(無公害食品)', 'price':5.00, 'count':2, 'total':10.02}, {'name':'旺菜', 'price':4.50, 'count':1, 'total':4.50}, {'name':'黃心番薯(有機食品)', 'price':4.50, 'count':1, 'total':4.50} ] } var hPos=10,//小票上邊距 pageWidth=580,//小票寬度 rowHeight=15,//小票行距 //獲取控件對象 LODOP=getLodop(document.getElementById(’LODOP_OB’),document.getElementById(’LODOP_EM’)); //初始化 LODOP.PRINT_INIT('打印控件功能演示_Lodop功能_名片'); //添加小票標題文本 LODOP.ADD_PRINT_TEXT(hPos,30,pageWidth,rowHeight,json.title); //上邊距往下移 hPos+=rowHeight; LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,'姓名:'); LODOP.ADD_PRINT_TEXT(hPos,30,pageWidth,rowHeight,json.name); //hPos+=rowHeight; //電話不換行 LODOP.ADD_PRINT_TEXT(hPos,70,pageWidth,rowHeight,'電話:'); LODOP.ADD_PRINT_TEXT(hPos,100,pageWidth,rowHeight,json.phone); hPos+=rowHeight; LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,'下單時間:'); LODOP.ADD_PRINT_TEXT(hPos,60,pageWidth,rowHeight,json.orderTime); hPos+=rowHeight; LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,'訂單編號:'); LODOP.ADD_PRINT_TEXT(hPos,60,pageWidth,rowHeight,json.orderNo); hPos+=rowHeight; LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,'取貨門店:'); LODOP.ADD_PRINT_TEXT(hPos,60,pageWidth,rowHeight,json.shop); hPos+=rowHeight; LODOP.ADD_PRINT_LINE(hPos,2, hPos, pageWidth,2, 1); hPos+=5; LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,'商品名稱'); LODOP.ADD_PRINT_TEXT(hPos,70,pageWidth,rowHeight,'單價'); LODOP.ADD_PRINT_TEXT(hPos,110,pageWidth,rowHeight,'數量'); LODOP.ADD_PRINT_TEXT(hPos,140,pageWidth,rowHeight,'小計'); hPos+=rowHeight; //遍歷json的商品數組 for(var i=0;i<json.goodsList.length;i++){ if(json.goodsList[i].name.length<4){ LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,json.goodsList[i].name); }else { //商品名字過長,其他字段需要換行 LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,json.goodsList[i].name); hPos+=rowHeight; } LODOP.ADD_PRINT_TEXT(hPos,70,pageWidth,rowHeight,json.goodsList[i].price); LODOP.ADD_PRINT_TEXT(hPos,115,pageWidth,rowHeight,json.goodsList[i].count); LODOP.ADD_PRINT_TEXT(hPos,140,pageWidth,rowHeight,json.goodsList[i].total); hPos+=rowHeight; } //商品遍歷打印完畢,空一行 hPos+=rowHeight; //合計 LODOP.ADD_PRINT_TEXT(hPos,80,pageWidth,rowHeight,'合計:'+json.totalCount); LODOP.ADD_PRINT_TEXT(hPos,130,pageWidth,rowHeight,'¥'+json.total); hPos+=rowHeight; LODOP.ADD_PRINT_TEXT(hPos,2,pageWidth,rowHeight,(new Date()).toLocaleDateString()+' '+(new Date()).toLocaleTimeString()) hPos+=rowHeight; LODOP.ADD_PRINT_TEXT(hPos,25,pageWidth,rowHeight,'謝謝惠顧,歡迎下次光臨!'); //初始化打印頁的規格 LODOP.SET_PRINT_PAGESIZE(3,pageWidth,45,'XXXXX訂單信息');}

javascript - Angular controlller控制域和原生js的關系

請問這是什么原因造成的呢?之前做過的一個項目在controller中寫原生的js也是可以用的啊,不知道這次為什么不可以

問題解答

回答1:

基礎性問題。

當在 use strict 模式下,function 應該遵循先定義后使用

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 亚洲精品日韩精品一区 | 免费看黄在线看 | 国产精品免费观看视频播放 | 本道久久综合88全国最大色 | 欧美在线视频一区二区三区 | 国产高清国内精品福利色噜噜 | 久草视频福利资源站 | 色一情一乱一乱91av | 久久国产精品高清一区二区三区 | 国产精品国产亚洲精品看不卡 | 春色视频一区二区三区 | a级毛片免费播放 | 香蕉在线观看999 | 精品一区国产 | 国产精品久久久久国产精品三级 | 黄色网在线免费观看 | 黄色一级大片视频 | 国产精品盗摄一区二区在线 | 成人午夜网址 | 亚洲免费黄色 | 一区二区三区高清在线 | 正在播放国产一区 | 俄罗斯胖老太与小伙交 | 色色视频在线观看 | 国产刚刚发育被强j在线播放 | 韩国淫片 | 亚洲精品国产精品乱码不卞 | 成人全黄三级视频在线观看 | 日韩aⅴ在线观看 | 免费一级欧美片片线观看 | 你懂的国产 | 91久久99热青草国产 | 欧美高清一级毛片免费视 | 在线播放亚洲精品富二代91 | 国产精品永久免费视频观看 | 日本亚洲色图 | 最新国产三级在线不卡视频 | 免费国产h视频在线观看86 | 拍拍拍无挡视频免费全程1000 | 日韩免费看片 | 婷婷视频网 |