最近uib-popoverで作業していますが、私は混乱しているという問題を発見しました。angle uib-popover-template入力双方向バインド
私はこのテンプレートで私は入力を持っている、最初に入力が初期値を持っている、テンプレートをpopoverしたい。
入力に基づいてコンテンツをリアルタイムで更新したいと考えています。変数をバインドするだけでは機能しませんが、オブジェクトをバインドすると機能します。私はこの問題を理解することはできません。ここで
index.htmlを
<!doctype html>
<html ng-app="ui.bootstrap.demo">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-animate.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-sanitize.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.4.0.js"></script>
<script src="example.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div ng-controller="PopoverDemoCtrl">
<hr/>
<hr/>
<hr/>
<button uib-popover-template="'myPopoverTemplate.html'" popover-placement="bottom-left" type="button" class="btn btn-default">Popover With Template</button>
{{dynamicPopover.title}}
<script type="text/ng-template" id="myPopoverTemplate.html">
<div class="form-group">
<input type="text" ng-model="dynamicPopover.title" class="form-control">
</div>
</script>
<button uib-popover-template="'inputContent.html'" popover-placement="bottom-left" type="button" class="btn btn-default">Popover With Template</button>
{{inputContent}}
<script type="text/ng-template" id="inputContent.html">
<div class="form-group">
<input type="text" ng-model="inputContent" class="form-control">
</div>
</script>
</div>
</body>
</html>
example.js
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('PopoverDemoCtrl', function($scope, $sce) {
$scope.dynamicPopover = {
title: 'Title'
};
$scope.inputContent = "hello";
});
plunker例https://plnkr.co/edit/IPXb5tddEPQPPAUrjdYx?p=previewである、あなたは、tryを持つことができます。
これは、変数は値によってバインドされ、オブジェクトはJavaScriptで参照によってバインドされているからだと思います。オブジェクトにバインドするだけで問題はありますか? –
あなたは[プリミティブとの双方向バインディングを持つことはできません](http://stackoverflow.com/questions/38078884/two-way-binding-on-primitive-variables-in-angularjs-directive) – RamblinRose
@big_water変数にバインドできない理由を理解したい –