Bootstrap 弹出窗口不更新范围变量
Bootstrap Popover not updating Scope Variable
一旦用户单击输入字段..我想获取输入字段的 ID 并过滤对象并将数据绑定到 Popover window。但是范围没有从指令中更新。下面是代码请让我知道我哪里做错了
var app = angular.module('MyModule', []);
app.controller("TestController", function ($scope, $window) {
//$scope.ID = '0';
$scope.myObj = [{ "ID": 0, "Name": 'user0' }, { "ID": 1, "Name": 'user1' }, { "ID": 2, "Name": 'user2' }]
$scope.GetData = function () {
var match = $.grep($scope.myObj, function (e) {
return e.ID == $scope.myID
});
return match;
};
});
app.directive('popOver', function ($compile, $timeout) {
return {
restrict: 'A',
link: function (scope, el, attrs) {
$(el).bind('click', function () {
scope.$apply(function () {
scope.myID = attrs.popoverid ;
});
});
$(el).popover({
placement: 'bottom',
container: 'body',
trigger: "click",
content: $compile($('#popover-content').html())(scope)
});
}
};
});
<div ng-repeat="i in [0,1,2]">
<input style="background: transparent"
type="text"
pop-over
popoverid="{{i}}"
id="{{i}}"
class="form-control enterTime" data-html="true">
<br /><br />
</div>
<div class="bottom hide" id="popover-content">
<div class="arrow" style="left: 47%;"></div>
<div class="Bground-Project">
<table>
<tr>
<td>
{{GetData()}}
</td>
</tr>
</table>
<button type="button" ng-click="buttonClicked()">click me</button>
</div>
</div>
当原始类型(即字符串、数字或布尔类型)写入时——例如,scope.name = newName——"write" 总是转到本地 scope/object。换句话说,子作用域有自己的名字 属性 来覆盖同名的父作用域 属性。解决方法是在父作用域中使用对象,而不是原始类型。然后子范围将获得对该对象的引用。对对象属性的任何写入(无论是来自父对象还是子对象)都将转到该对象。 (子作用域没有得到自己的对象。)
Is it Possible to Update Parent Scope from Angular Directive with scope: true?
一旦用户单击输入字段..我想获取输入字段的 ID 并过滤对象并将数据绑定到 Popover window。但是范围没有从指令中更新。下面是代码请让我知道我哪里做错了
var app = angular.module('MyModule', []);
app.controller("TestController", function ($scope, $window) {
//$scope.ID = '0';
$scope.myObj = [{ "ID": 0, "Name": 'user0' }, { "ID": 1, "Name": 'user1' }, { "ID": 2, "Name": 'user2' }]
$scope.GetData = function () {
var match = $.grep($scope.myObj, function (e) {
return e.ID == $scope.myID
});
return match;
};
});
app.directive('popOver', function ($compile, $timeout) {
return {
restrict: 'A',
link: function (scope, el, attrs) {
$(el).bind('click', function () {
scope.$apply(function () {
scope.myID = attrs.popoverid ;
});
});
$(el).popover({
placement: 'bottom',
container: 'body',
trigger: "click",
content: $compile($('#popover-content').html())(scope)
});
}
};
});
<div ng-repeat="i in [0,1,2]">
<input style="background: transparent"
type="text"
pop-over
popoverid="{{i}}"
id="{{i}}"
class="form-control enterTime" data-html="true">
<br /><br />
</div>
<div class="bottom hide" id="popover-content">
<div class="arrow" style="left: 47%;"></div>
<div class="Bground-Project">
<table>
<tr>
<td>
{{GetData()}}
</td>
</tr>
</table>
<button type="button" ng-click="buttonClicked()">click me</button>
</div>
</div>
当原始类型(即字符串、数字或布尔类型)写入时——例如,scope.name = newName——"write" 总是转到本地 scope/object。换句话说,子作用域有自己的名字 属性 来覆盖同名的父作用域 属性。解决方法是在父作用域中使用对象,而不是原始类型。然后子范围将获得对该对象的引用。对对象属性的任何写入(无论是来自父对象还是子对象)都将转到该对象。 (子作用域没有得到自己的对象。)
Is it Possible to Update Parent Scope from Angular Directive with scope: true?