比较两个字符串并使用角度js获取不常见的单词strikeoff

时间:2016-07-25 08:04:33

标签: javascript angularjs

我必须比较两个字符串并得到不常见的结果。 我已经尝试了下面的代码,它给出输出结果比较是真还是假。 我想在变量中得到不常见的单词的结果。

<div ng-app="myApp" ng-controller="myCtrl">
  <form novalidate>
    <h3>User 1</h3>
    Name: <input type="text" ng-model="user1.name">
    Age: <input type="number" ng-model="user1.age">

    <h3>User 2</h3>
    Name: <input type="text" ng-model="user2.name">
    Age: <input type="number" ng-model="user2.age">

    <div>
      <br/>
      <input type="button" value="Compare" ng-click="compare()">
    </div>
    User 1: <pre>{{user1 | json}}</pre>
    User 2: <pre>{{user2 | json}}</pre>
    Equal: <pre>{{result}}</pre>
    Uncommon words: <pre>{{compare}}</pre>
  </form>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.firstName = "John";
    $scope.lastName = "Doe";

 $scope.user1 = {};
  $scope.user2 = {};
  $scope.result;

  $scope.compare = function() {
    $scope.result = angular.equals($scope.user1, $scope.user2);
  };

});
</script>

有人可以建议我继续这个吗?

0 个答案:

没有答案