単にnewCreative.companionUrl
がスコープ内に存在するかどうかを確認するためにng-if
を使用します。
<div class="form-group">
<div class="text-form" style="float: left;">Companion URL</div>
<input type="text" placeholder="Companion URL" class="companion-url-box" ng-model="newCreative.companionUrl">
<input type="button" value="Click me" ng-if="newCreative.companionUrl">
</div>
ます。また、ボタンの可視性を検証する機能を使用することができます。
index.htmlを
<!doctype html>
<html lang="en" ng-app="app">
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>
<script src="scripts.js"></script>
</head>
<body ng-controller="SampleController as ctrl">
<div class="form-group">
<div class="text-form" style="float: left;">Companion URL</div>
<input type="text" placeholder="Companion URL" class="companion-url-box" ng-model="newCreative.companionUrl">
<input type="button" value="Click me" ng-if="ctrl.isButtonAvailable()">
</div>
</body>
</html>
script.js
angular.module('app', []);
angular.module('app').controller('SampleController', function ($scope) {
var ctrl = this;
ctrl.isButtonAvailable = function() {
if(!$scope.newCreative) {
return false;
}
// Ensure companion url starts with https:// using a regular expression
return /^https:\/\//.test($scope.newCreative.companionUrl);
}
});
の作業例
このPlunkerをチェックアウト:https://plnkr.co/edit/n8VtJrenePGf9hCbmzWJ
何の条件に基づいてテキストの変更はボタンつもりが追加されます? –
申し訳ございませんが、 –
https://www.w3schools.com/angular/tryit.asp?filename=try_ng_ng-changeの質問とng-chageの例が分かりません。AngularJSサイトを次のように確認してください。よくhttps://docs.angularjs.org/api/ng/directive/ngChange – poohbear