$ parse:syntax AngularJS中的语法错误

时间:2016-03-24 06:25:58

标签: angularjs

我有一个程序可以根据作者排序单词,这是一个数组。我收到控制台中的$ parse:语法错误;但是,程序正在执行并返回正确的结果。我不确定导致这个问题的原因。我正在使用其他属性(如标签和书籍)对单词进行排序;但是,此控制台错误仅由这些阵列中的某些实例显示。

它的外观如下: view

错误如下:

angular.js:13236 Error: [$parse:syntax] Syntax Error: Token 'Baggins' is an unexpected token at column 7 of the expression [Frodo Baggins] starting at [Baggins].
http://errors.angularjs.org/1.5.0/$parse/syntax?p0=Baggins&p1=is%20an%20unexpected%20token&p2=7&p3=Frodo%20Baggins&p4=Baggins
    at http://localhost:8080/node_modules/angular/angular.js:68:12
    at Object.AST.throwError (http://localhost:8080/node_modules/angular/angular.js:13816:11)
    at Object.AST.ast (http://localhost:8080/node_modules/angular/angular.js:13586:12)
    at Object.ASTCompiler.compile (http://localhost:8080/node_modules/angular/angular.js:14040:31)
    at Parser.parse (http://localhost:8080/node_modules/angular/angular.js:14927:29)
    at $parse (http://localhost:8080/node_modules/angular/angular.js:15035:39)
    at http://localhost:8080/node_modules/angular/angular.js:20463:17
    at Array.map (native)
    at processPredicates (http://localhost:8080/node_modules/angular/angular.js:20452:26)
    at http://localhost:8080/node_modules/angular/angular.js:20416:22(anonymous function) @ angular.js:13236(anonymous function) @ angular.js:9965Scope.$digest @ angular.js:16682Scope.$apply @ angular.js:16928clickListener @ angular-material.js:14066defaultHandlerWrapper @ angular.js:3398eventHandler @ angular.js:3386
angular.js:13236 Error: [$parse:syntax] Syntax Error: Token 'Baggins' is an unexpected token at column 7 of the expression [Frodo Baggins] starting at [Baggins].
http://errors.angularjs.org/1.5.0/$parse/syntax?p0=Baggins&p1=is%20an%20unexpected%20token&p2=7&p3=Frodo%20Baggins&p4=Baggins
    at http://localhost:8080/node_modules/angular/angular.js:68:12
    at Object.AST.throwError (http://localhost:8080/node_modules/angular/angular.js:13816:11)
    at Object.AST.ast (http://localhost:8080/node_modules/angular/angular.js:13586:12)
    at Object.ASTCompiler.compile (http://localhost:8080/node_modules/angular/angular.js:14040:31)
    at Parser.parse (http://localhost:8080/node_modules/angular/angular.js:14927:29)
    at $parse (http://localhost:8080/node_modules/angular/angular.js:15035:39)
    at http://localhost:8080/node_modules/angular/angular.js:20463:17
    at Array.map (native)
    at processPredicates (http://localhost:8080/node_modules/angular/angular.js:20452:26)
    at http://localhost:8080/node_modules/angular/angular.js:20416:22(anonymous function) @ angular.js:13236(anonymous function) @ angular.js:9965Scope.$digest @ angular.js:16682processQueue @ angular-material.js:1316(anonymous function) @ angular.js:18744completeOutstandingRequest @ angular.js:5804(anonymous function) @ angular.js:6081

JSON如下

{
"expression": "to the day",
"meaning": "",
"example": "it's been four years to the day.",
"pronunciation": "",
"notes": "",
"meta": {
"book": ["There and back again"],
"author": ["Frodo Baggins"],
"tags": ["middle earth"]}
},

视图中的代码如下:

<md-input-container>
        <label>Books</label>
        <md-select ng-model="book">
            <md-option ng-repeat="book in books | orderBy: book" value="{{ book }}"> <!-- books here refers to a newly defined array that stores only one instance of all the books against the 'book' property on each object/word -->
                {{ book }} 
            </md-option>
        </md-select>
    </md-input-container>

控制器中的代码如下:

function getBooks(classifieds) {

        var books = [];
        angular.forEach(classifieds, function(item) {
            if (item.meta) {    
                angular.forEach(item.meta.book, function(b) {

                    books.push(b);
                });
            }

        });

        return _.uniq(books);

    }

1 个答案:

答案 0 :(得分:0)

我认为简单的答案 - 顺序应为:| orderBy:'book' https://docs.angularjs.org/api/ng/filter/orderBy