Javascript AngularJS、NodeJs和ExpressJS
该计划只是做一个总结,学习如何工作角度,表达和节点 我的图书馆是: angular.js angular-route.js 我正在尝试运行此代码,但发现错误:Javascript AngularJS、NodeJs和ExpressJS,javascript,html,angularjs,node.js,Javascript,Html,Angularjs,Node.js,该计划只是做一个总结,学习如何工作角度,表达和节点 我的图书馆是: angular.js angular-route.js 我正在尝试运行此代码,但发现错误: Uncaught TypeError: url.match is not a function (13:04:31:527 | error, javascript) at completeRequest (public_html/js/libs/angular.js/angular.js:10437:27) at xhr.onr
Uncaught TypeError: url.match is not a function (13:04:31:527 | error, javascript)
at completeRequest (public_html/js/libs/angular.js/angular.js:10437:27)
at xhr.onreadystatechange (public_html/js/libs/angular.js/angular.js:10404:11)
我的HTML是:
我的AngularJS脚本:
(function(angular) {
'use strict';
angular.module('myCalc', ['ngRoute'])
.controller('AppCtrl', function($scope, $http, $templateCache) {
$scope.click = function(url) {
$scope.url = url;
var param1 = $scope.param1;
var param2 = $scope.param2;
$http.get({ url: $scope.url, param1: $scope.param1, param2: $scope.param2, cache: $templateCache}).
// $http.get({ url: $scope.url, cache: $templateCache}).
success(function(data) {
$scope.data = data;
}).
error(function(data) {
$scope.data = data || "Request failed";
});
};
})
.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('http://localhost:8000/calc/param1/:param1/param2/:param2', {
templateUrl: 'index.html',
controller: 'AppCtrl'
// configure html5 to get links working on jsfiddle
$locationProvider.html5Mode(true);
});
})(window.angular);
您以错误的方式将
url
和params
传递给
$http.get(url,{configjson})
因为它的第一个参数是url,第二个参数用于配置
代码
$http.get($scope.url, {
params: {
param1: $scope.param1,
param2: $scope.param2
},
cache: $templateCache
}).
success(function(data) {
$scope.data = data;
}).
error(function(data) {
$scope.data = data || "Request failed";
});
嗨pankajparkar非常感谢你伙计。你是对的!!你的解释帮了大忙@罗德里戈姆:请你把这个答案标记为正确:)
(function(angular) {
'use strict';
angular.module('myCalc', ['ngRoute'])
.controller('AppCtrl', function($scope, $http, $templateCache) {
$scope.click = function(url) {
$scope.url = url;
var param1 = $scope.param1;
var param2 = $scope.param2;
$http.get({ url: $scope.url, param1: $scope.param1, param2: $scope.param2, cache: $templateCache}).
// $http.get({ url: $scope.url, cache: $templateCache}).
success(function(data) {
$scope.data = data;
}).
error(function(data) {
$scope.data = data || "Request failed";
});
};
})
.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('http://localhost:8000/calc/param1/:param1/param2/:param2', {
templateUrl: 'index.html',
controller: 'AppCtrl'
// configure html5 to get links working on jsfiddle
$locationProvider.html5Mode(true);
});
})(window.angular);
$http.get($scope.url, {
params: {
param1: $scope.param1,
param2: $scope.param2
},
cache: $templateCache
}).
success(function(data) {
$scope.data = data;
}).
error(function(data) {
$scope.data = data || "Request failed";
});