小编Pet*_*sma的帖子

TypeError:无法使用Angular读取undefined的属性'comments'

我正在关注本教程当我尝试在帖子上发表评论时,我TypeError: Cannot read property 'comments' of undefined在控制台中收到错误消息.

mainCtrl,

.controller('mainCtrl', ['$scope', 'posts',
  function($scope, posts){
    $scope.posts = posts.posts;

  $scope.addPost = function(){
    if(!$scope.title || $scope.title === '') { alert("Field can't left blank"); return; }

    $scope.posts.push({
      title: $scope.title,
      upvotes: 0,
      comments: [
        {author: 'Joe', body: 'Cool post!', upvotes: 0},
        {author: 'Bob', body: 'Great idea but everything is wrong!', upvotes: 0}
      ]
    });
  };
  }
])
Run Code Online (Sandbox Code Playgroud)

和postCtrl,

.controller('PostsCtrl', ['$scope', '$stateParams', 'posts',
  function($scope, $stateParams, posts){
    $scope.post = posts.posts[$stateParams.id];

    $scope.addComment = function(){
      if($scope.body === …
Run Code Online (Sandbox Code Playgroud)

angularjs

6
推荐指数
1
解决办法
5754
查看次数

Visual Studio Code 中 Spring Boot 中的热交换

我刚刚使用 Angular 4 启动了一个 Spring Boot 项目。对于 Angular,我可以运行,npm start以便 NPM 编译每个更改。但我不知道如何为 Spring Boot 做到这一点。我可以找到 Eclipse/IntelliJ 的一些来源,但我想继续使用我的 Visual Studio Code 编辑器。

spring

6
推荐指数
2
解决办法
4269
查看次数

如何使用Angular暂停setInterval?

我有一个播放和一个暂停按钮:

<div *ngIf="!playToggle">
    <button (click)="playTimeLine(); playToggle = true">
        <i class="fa fa-play" aria-hidden="true"></i>
    </button>
</div>
<div *ngIf="playToggle">
    <button (click)="pauseTimeLine(); playToggle = false">
        <i class="fa fa-pause" aria-hidden="true"></i>
    </button>
</div>
Run Code Online (Sandbox Code Playgroud)

如果单击播放按钮,则调用该playTimeLine函数:

currentTime = 0;

playTimeLine(value) {

    setInterval(() => {
        this.currentTime = this.currentTime + 10;
        console.log(this.currentTime);
    }, 1000);
}
Run Code Online (Sandbox Code Playgroud)

我想添加暂停功能,暂停间隔.但它也可以从暂停时恢复它.

javascript angular

6
推荐指数
2
解决办法
3245
查看次数

检查 scrollTo 以完成

我有一个可滚动的元素。我还有一个滚动到特定位置的功能。我想在 scrollTo 完成后调用一个函数。

Plunkr 示例

var x = document.querySelector('.container');
$scope.scrollTo = function() {
  x.scrollTo({
    top: 300 ,
    behavior: 'smooth'
  });
};

 // do something when scrollTo is finished
Run Code Online (Sandbox Code Playgroud)

javascript angularjs

6
推荐指数
2
解决办法
4587
查看次数

返回具有最高值的对象

我有一个名为带有值的游戏数组votes,

let games = [
    { id: 1, name: 'Star Wars: Imperial Assault', company: company.Fantasy_Flight, available: true, category: Category.SciFi, votes: 3},
    { id: 2, name: 'Game of Thrones: Second Edition', company: 'Fantassy Flight', available: false, category: Category.Fantasy, votes: 4 },
    { id: 3, name: 'Merchans and Marauders', company: 'Z-Man Gaming', available: true, category: Category.Pirates, votes: 5 },
    { id: 4, name: 'Eclipse', company: 'Lautapelit', available: false, category: Category.SciFi, votes: 6 },
    { id: 5, name: 'Fure of Dracula', …
Run Code Online (Sandbox Code Playgroud)

javascript

5
推荐指数
2
解决办法
1757
查看次数

Passport Facebook回调停滞不前

我使用passport-facebook登录我的用户,但看起来回调不正常.当我尝试登录时,它会在chrome网络标签中显示一条待处理的请求:

HTTP://本地主机:3000/AUTH /实/回调代码=****_ 46H1el1ysca5wloo8PX7iWxdVGGavNgiFOp4rKv63pH6b5IVcaWntTLF6u4kpnb2PYWShhdRb8jVPiknwd0_wvyFTvVTAWevwwfTE6zAPk10g9gX6qmlAIWwi3XKz3FCOEB8j_c_hF7nI4I3beD52TUI5jIrgWqWdubzDvpzlZsgve7-ThFZJO-hSFByyY4VKiw3UMw_keQxhDgOORKthe8Dh_tyhP8sjVJ8lxvhSQstP7IbaBqtwa0DgxCToVOQkUILphzThd6dVrFIFAaf0VbVYrgQdWoSSDKJWnh0CPLWEkB6I7aU63iRO6ew527XZ8BUgCDHONNSQ2b1jT-

过了一会儿,请求失败,状态为500.这就是我的Node服务器显示的内容:

GET /auth/facebook 302 1.602 ms - 0
GET /auth/facebook/callback?code=***_EC2RZfeVmZPO26_GNC01khGONZ67hPUae2BMbaLnSAUWFDNYH9zAVuegm1EPJM3QOtgF821np0pAYGo0UeZgwEPb07R5p3UXtOi18vGy6I2QIYAOLbxpXPZ3Kbg6PKlQkuyI6upWB7vHnMHcSm6eybe0l5TjCkli9vmEXRM9Rmvv3uGu8n0fhSyLkzDqS8CDGsKBwdmW4wmNuL5pc-OaHHsVvguFlnZW4gvCvhhOJ3qle6p6dcIJa-1XAuRgKEukRXn8w7oxF_ueIHvO9cm6iGzvAkIOCfWIlY-wdm-ounTGH6EWhZuVUtRbWsq5kLxxuDPfRbKrhtDNeYWbuBV - - ms - -
GET /auth/facebook/callback?code=****_EC2RZfeVmZPO26_GNC01khGONZ67hPUae2BMbaLnSAUWFDNYH9zAVuegm1EPJM3QOtgF821np0pAYGo0UeZgwEPb07R5p3UXtOi18vGy6I2QIYAOLbxpXPZ3Kbg6PKlQkuyI6upWB7vHnMHcSm6eybe0l5TjCkli9vmEXRM9Rmvv3uGu8n0fhSyLkzDqS8CDGsKBwdmW4wmNuL5pc-OaHHsVvguFlnZW4gvCvhhOJ3qle6p6dcIJa-1XAuRgKEukRXn8w7oxF_ueIHvO9cm6iGzvAkIOCfWIlY-wdm-ounTGH6EWhZuVUtRbWsq5kLxxuDPfRbKrhtDNeYWbuBV FacebookTokenError: This authorization code has been used.
    at Strategy.parseErrorResponse (C:\Users\alucardu\IdeaProjects\movieseat-2.0\node_modules\passport-facebook\lib\strategy.js:196:12)
500 172.152 ms - 1326
at Strategy.OAuth2Strategy._createOAuthError (C:\Users\alucardu\IdeaProjects\movieseat-2.0\node_modules\passport-facebook\node_modules\passport-oauth2\lib\strategy.js:367:16)
at C:\Users\alucardu\IdeaProjects\movieseat-2.0\node_modules\passport-facebook\node_modules\passport-oauth2\lib\strategy.js:166:45
at C:\Users\alucardu\IdeaProjects\movieseat-2.0\node_modules\passport-facebook\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:177:18
at passBackControl (C:\Users\alucardu\IdeaProjects\movieseat-2.0\node_modules\passport-facebook\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:123:9)
at IncomingMessage.<anonymous> (C:\Users\alucardu\IdeaProjects\movieseat-2.0\node_modules\passport-facebook\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:143:7)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:913:12)
at nextTickCallbackWith2Args (node.js:442:9)
Run Code Online (Sandbox Code Playgroud)

错误说明:

FacebookTokenError:已使用此授权码.

我也refreshToken得到了不确定,虽然我不知道多少重要.

这是我的facebook路线:

router.get('/facebook', passport.authenticate('facebook', {
  scope: ['email']
}));

router.get('/facebook/callback', passport.authenticate('facebook', {
    successRedirect: '/',
    failureRedirect: …
Run Code Online (Sandbox Code Playgroud)

express passport-facebook passport.js

5
推荐指数
0
解决办法
445
查看次数

已超过“max_user_connections”资源

我有一个 MySQL、Express、Angular、NodeJS 应用程序,有时当我登录时,我的节点控制台中出现以下错误:

类型错误:无法读取未定义的属性“查询”

错误发生在我的passport.local.js文件中,这是一行:

connection.query('SELECT * FROM users WHERE username LIKE ?', [username], function (err, user) {
Run Code Online (Sandbox Code Playgroud)

这是护照功能

passport.use(new LocalStrategy(
    function(username, password, done) {

        console.log('app.js');

        pool.getConnection(function(err, connection) {

            console.log('err: ' + err);
            console.log(connection);    

            connection.query('SELECT * FROM users WHERE username LIKE ?', [username], function (err, user) {
                if (err) throw err;

                for (var i = user.length - 1; i >= 0; i--) {
                    var current = user[i];
                }

                if(current){
                    if(bcrypt.compareSync(password, current.password)){
                        return done(null, user);
                    } else {
                        return …
Run Code Online (Sandbox Code Playgroud)

mysql node.js express

5
推荐指数
2
解决办法
3万
查看次数

Azure 向变量添加前导空格

如果我在本地运行此 powershell 代码:

$url = "refs/pull/5625/merge"
$SourceBranchFromBuild = $url.split('/')[-1]
$featureReleaseUrl = "http://$sourceBranchFromBuild.azurewebsites.net"
Write-Output $featureReleaseUrl
Run Code Online (Sandbox Code Playgroud)

输出是:

http://merge.azurewebsites.net

当我在 Azure Powershell 上运行此代码时:

$url = "refs/pull/5625/merge"
$SourceBranchFromBuild = $url.split('/')[-1]
Write-Host "##vso[task.setvariable variable=prSourceBranchName;]"$SourceBranchFromBuild
Run Code Online (Sandbox Code Playgroud)

然后在另一个 Azure Powershell 脚本中创建 URL:

$featureReleaseUrl = "http://$env:prSourceBranchName.azurewebsites.net"
Write-Output $featureReleaseUrl
Run Code Online (Sandbox Code Playgroud)

输出是

http://merge.azurewebsites.net

是什么导致了这个前导空格字符$env:prSourceBranchName

powershell azure

5
推荐指数
1
解决办法
1438
查看次数

类型“boolean”不可分配给类型“false”

我正在与其他几个人一起开发一个应用程序,今天我拉了master,在构建过程中突然收到一个错误:

类型“boolean”不可分配给类型“false”。

另一位同事也遇到了这个问题,但其他几个开发人员没有遇到这个问题。我们都运行相同的 tsconfig.json。

我已经更新了 TypeScript,我们都在运行 Node v10+。

什么可能导致我们的系统之间存在差异?

typescript

5
推荐指数
1
解决办法
8322
查看次数

MUI 有表单组件吗?

我有一个包含多个FormControlhttps://mui.com/api/form-control/)组件的表单,我将它们包装在:

const FormBody = styled(Box)(() => ({
  display: 'flex',
  flexDirection: 'column',
}));
Run Code Online (Sandbox Code Playgroud)
<FormBody onSubmit={handleSubmitLogin(onLoginSubmit)} component="form">
  <FormControl>
  ...
Run Code Online (Sandbox Code Playgroud)

但我希望在 MUI 主题中创建一些 CSS 规则,但我找不到任何可用于封装组件的组件FormControl

reactjs material-ui

5
推荐指数
1
解决办法
2106
查看次数