2017-04-05 3 views
0

Angular JSの新機能です。しかし、1行または単純な解決策を見つけることができませんでした。 入力テキストボックスで「残りの文字数」を達成しようとしていますが、explorationObjectiveService.displayedの値はundefinedです。ヘルプは高く評価しました。このsinppest月はあなたを助け

HTML

<input id="explorationObjective" type="text" 
        class="form-control protractor-test-exploration-objective-input" 
        ng-model="explorationObjectiveService.displayed" 
        ng-blur="saveExplorationObjective()" placeholder="Learn how to ..." maxlength="100"> 

指令JS

$scope.counter= 100 - ($scope.explorationObjectiveService.displayed).length; 
+0

間違っ括弧:($スコープ。経験lorationObjectiveService.displayed.length); – Groben

+0

かっこは何も影響しません@Groben – taguenizy

+0

指令スクリプトを追加してください –

答えて

0

チェック....

var app = angular.module('plunker', []); 
 

 
app.controller('MainCtrl', function($scope) { 
 
    $scope.num=100; 
 
    $scope.change = function(){ 
 
    $scope.num=100-$scope.data.length 
 
    }; 
 
});
<!DOCTYPE html> 
 
<html ng-app="plunker"> 
 

 
    <head> 
 
    <meta charset="utf-8" /> 
 
    <title>AngularJS Plunker</title> 
 
    <script>document.write('<base href="' + document.location + '" />');</script> 
 
    <link rel="stylesheet" href="style.css" /> 
 
    <script data-require="[email protected]" src="https://code.angularjs.org/1.4.12/angular.js" data-semver="1.4.9"></script> 
 
    <script src="app.js"></script> 
 
    </head> 
 

 
    <body ng-controller="MainCtrl"> 
 
    <p>Hello {{name}}!</p> 
 
    <input id="explorationObjective" type="text" 
 
        class="form-control protractor-test-exploration-objective-input" 
 
        ng-model="data" 
 
        ng-change="change()" placeholder="Learn how to ..." maxlength="100"> 
 
        <p>remained: {{num }}chars</p> 
 
    </body> 
 

 
</html>

+0

このコードは問題の解決に役立つかもしれませんが、_why_および/または_how_が質問に答えているとは説明していません。この追加の文脈を提供することは、長期的な価値を大幅に改善することになる。どのような制限や仮定が適用されるかなど、あなたの答えを解説してください。 –

関連する問題