小编sim*_*aur的帖子

意外的令牌<在HTML的第一行

我有一个HTML文件:

<!DOCTYPE HTML>
<html lang="en-US" ng-app="Todo">
<head>
    <meta charset="UTF-8">
    <title>DemoAPI</title>

  <meta name="viewport">

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>

<link rel="stylesheet" href="./Client/css/styling.css" />
<script type="text/javascript" src="core.js"></script>

</head>
Run Code Online (Sandbox Code Playgroud)

错误说:

Uncaught SyntaxError: Unexpected token <    core.js: 1
Run Code Online (Sandbox Code Playgroud)

它显示了在错误<!doctype html>app.html.

core.js 看起来像这样:

angular.module('Todo', [])

.controller('mainController', function($scope, $http)
{
    $scope.formData = {};

    // get all and show them
    $http.get('/musicians')
        .success(function(data) {
            $scope.todos = data;
            console.log(data);
        })
        .error(function(data) {
            console.log('Error: ' + data);
        });

        //get with an id
        $scope.getOneTodo = …
Run Code Online (Sandbox Code Playgroud)

html javascript syntax-error uncaught-exception

60
推荐指数
2
解决办法
11万
查看次数

window.setInterval无法处理angularjs

我有一小段使用setInterval方法的代码:

function MyController($scope) {
    $scope.clock = new Date();
    var updateClock = function() {
        $scope.clock = new Date();
    };
    setInterval(updateClock, 1000);
};
Run Code Online (Sandbox Code Playgroud)

和html如下:

<!doctype html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.js"></script>
</head>
<body>
    <div ng-controller="MyController">
        <h1>Hello {{ clock }}!</h1>
    </div>
    <script type="text/javascript" src="script.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

但是,setIntervalMyController不更新时间.哪里可能有问题?

它按照这本书的方式工作:

function MyController($scope) {
    $scope.clock = new Date();
    var updateClock = function() {
        $scope.clock = new Date();
    };
    setInterval(function() {
        $scope.$apply(updateClock);
    }, 1000);
    updateClock();
};
Run Code Online (Sandbox Code Playgroud)

如果没有使用@ scope,为什么会出现问题?$ apply?

javascript angularjs

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

c中的循环迭代

#include<stdio.h>
int main()
{
    int i,x=10;
    for(i=0;i<7;i++);
    {
        x++;
    }
    printf("%d",x);
}
Run Code Online (Sandbox Code Playgroud)

产量: 11

无论for循环迭代多少次,x的值都保持为11.为什么呢?

c

-1
推荐指数
1
解决办法
73
查看次数