我尝试在angularjs中创建服务,但我一直在获得angular.js:10467错误:[ng:areq]参数'MainController'不是函数,未定义.
HTML:
<div ng-controller="MainController">
<form name="searchUser" method="post">
<input ng-model="username" type="search" placeholder="Find"/>
<input type="submit" value="Search" ng-click="search(username)" />
</form>
You are searching for: {{username}}
<hr />
<div ng-repeat="(key,value) in data">
{{ key + " : " + value}}
</div>
</div>
<script src="lib/angular/angular.js"></script>
<script src="js/app.js"></script>
<script src="services/Screamer.js"></script>
Run Code Online (Sandbox Code Playgroud)
我的app.js:
angular.module('NoteTaker', []); // dependcies in array.
angular.module('NoteTaker', []).controller('MainController', function(screamer, $log, $http, $scope, $interval){
$http({
method : 'GET',
url: 'https://api.github.com/users/' + $scope.username
}).then(function(response){
console.log(response);
$scope.data = response.data;
}, function(response){
console.log(response);
});
Run Code Online (Sandbox Code Playgroud)
我在service.js的服务
(function() {
'use strict'; …Run Code Online (Sandbox Code Playgroud) 我试图在模板之外声明一个成员函数 - GetValue.
我收到错误:main.cpp | 16 |错误:重新定义'GenericType Test :: GetValue()'| |错误:'GenericType Test :: GetValue()'先前在这里声明|
#include <iostream>
template <class GenericType>
class Test {
public:
GenericType x;
Test(){ }
Test(int y) : x( y){ }
GenericType GetValue(){}
};
template <class GenericType>
GenericType Test<GenericType>::GetValue(){
return x;
}
int main()
{
Test<int> y(5);
std::cout << y.GetValue();
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我的静态topStock方法有什么问题?它引用了股票和股票t.它不应该返回s或t的副本吗?
错误:'.'之前的预期primary-expression 令牌|
#include <iostream>
using namespace std;
class Stock {
public:
Stock() : x(0){ }
Stock(int val) : x(val){}
void display() const;
static Stock topStock(const Stock& s, const Stock& t) {
if (s.x > t.x)
return s;
else
return t;
}
int x;
};
void Stock::display() const
{
std::cout << this->x;
}
int main()
{
Stock s(9);
Stock y(8);
Stock z = Stock.topStock(s, y);
return 0;
}
Run Code Online (Sandbox Code Playgroud) Samurai依赖于ninja.chirp,但我删除了对ninja.chirp的引用.为什么这段代码继续有效?
var ninja = {
chirp: function (n) {
return n > 1 ? this.chirp(n - 1) + '-chirp' : 'chirp';
}
};
function chirp(n) {
return n > 1 ? chirp(n-1) + '-chirp' : 'chirp';
}
var samurai = {
chirp: ninja.chirp
};
ninja = {};
try {
console.log(samurai.chirp(3));
}
catch (e) {
console.log("no can do.");
}
</script>
Run Code Online (Sandbox Code Playgroud) 我无法弄清楚为什么我的lambda错了.它应该创建一个make-exp.
(define (exp b n)
(if (n = 0)
1
(* b (exp b (- n 1)))))
(define make-exp (lambda(n) (lambda(b)(exp b n ))))
(define square (make-exp 2))
(square 3)
Run Code Online (Sandbox Code Playgroud)
错误:2不是函数[square,exp,(anon)]
我需要帮助试图弄清楚为什么我的指针数组不起作用.我正在递增指针地址和I.我的控制台窗口只是挂起.
int *arr = new int[10];
int i = 0;
while (i < 10){
*arr = i; // assign the value of arr to i
arr++; // increment the pointer by 1
i++; // increment i
}
delete[] arr;
Run Code Online (Sandbox Code Playgroud)