在angularjs中是/ else语句

时间:2016-04-12 08:39:17

标签: javascript angularjs node.js

我想将输入的inputLanguage更改为值' en'。当我尝试这种方法时,他们返回的错误是英语没有定义。

这是我的alchemy.js

    module.exports = function(Alchemy) {
 Alchemy.language = function(inText, inputLanguage, outputLanguage, cb) {
    console.log('Input text is ' + inText);
    console.log('Input language is ' + inputLanguage);
    console.log('Output language is ' + outputLanguage);
    getCode(inputLanguage, outputLanguage, cb);
  }

  Alchemy.remoteMethod(
    'language', {
      http: {
        path: '/language',
        verb: 'get'
      },
      accepts: [{
        arg: 'inText',
        type: 'string',
        required: true
      }, {
        arg: 'inputLanguage',
        type: 'string',
        required: true
      }, {
        arg: 'outputLanguage',
        type: 'string',
        required: true
      }],
      returns: {
        arg: 'results',
        type: 'string'
      }
    }
  );
  function getCode(inputLanguage, outputLanguage, cb) {
      if (inputLanguage = english) {
          inLang = en;
          console.log('Input language is ' + inlang)
      }
  }
};

2 个答案:

答案 0 :(得分:1)

问题在块if (inputLanguage = english)

首先,english是未定义的变量,因此要对其进行定义,或者如果要将其更改为字符串,请添加引号。

第二个问题是=符号,单个=是分配,如果要比较变量,则需要使用=====

答案 1 :(得分:0)

您对<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="myapp" ng-controller="myctrl"> <input ng-model="filter" placeholder="filter" /> <ul class="filter-ul" ng-repeat="brand in brands | filter: {vendor: {name: filter}}"> <li class="filter-li">{{ brand.name }}</li> </ul> </div>,变量和字符串的工作方式感到困惑。既没有名为if的变量,也没有english - en分配,===正在检查等式=&gt; see here

尝试使用以下内容:

===

在JS中,字符串由if (inputLanguage === 'english') { inLang = 'en'; console.log('Input language is ' + inlang) } "

括起来