Angular 模式中的变量 UI 未观看
Variable in Angular Modal UI not watched
In this plunk 我有一个 Angular Modal UI 有一个被监视的变量,但是当变量改变时监视功能没有被触发,怎么了?
Javascript
var app = angular.module('app', ['ui.bootstrap']);
app.controller('ctl', function ($scope,$uibModal) {
$scope.x = 'a';
$scope.open = function(){
$scope.modalInstance = $uibModal.open({
templateUrl: 'myModalContent.html',
scope: $scope
});
};
$scope.close = function(){
$scope.modalInstance.close();
};
$scope.$watch('x', function (newValue, oldValue) {
if (typeof newValue === 'undefined')
return;
alert('value='+$scope.newValue);
});
});
HTML
<button ng-click="open()">Open</button>
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h4 class="modal-title">The Title</h4>
value <input type="text" ng-model="x" />
<button ng-click="close()">Close</button>
</div>
</script>
请在$uibModal.open中定义控制器更多参考请访问此文档详细
https://github.com/angular-ui/bootstrap/tree/master/src/modal/docs
刚刚在 plunker 中测试,$uibModal 需要您的控制器才能绑定到您的范围。
改变;
$scope.open = function(){
$scope.modalInstance = $uibModal.open({
templateUrl: 'myModalContent.html',
scope: $scope
});
};
致;
$scope.open = function(){
$scope.modalInstance = $uibModal.open({
templateUrl: 'myModalContent.html',
scope: $scope,
controller: "ctl"
});
};
如果您使用的是 .js 文件,则应使用 controllerUrl = "path/to/jsfile.js" 加上所述控制器的名称。
这个问题有助于解决 $uibModal onload 事件
刚刚添加到 modalController
$scope.open = function () {
$scope.status.opened = true;
};
$scope.$watch(status, function (newValue, oldValue) {
//code required onload..
});
In this plunk 我有一个 Angular Modal UI 有一个被监视的变量,但是当变量改变时监视功能没有被触发,怎么了?
Javascript
var app = angular.module('app', ['ui.bootstrap']);
app.controller('ctl', function ($scope,$uibModal) {
$scope.x = 'a';
$scope.open = function(){
$scope.modalInstance = $uibModal.open({
templateUrl: 'myModalContent.html',
scope: $scope
});
};
$scope.close = function(){
$scope.modalInstance.close();
};
$scope.$watch('x', function (newValue, oldValue) {
if (typeof newValue === 'undefined')
return;
alert('value='+$scope.newValue);
});
});
HTML
<button ng-click="open()">Open</button>
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h4 class="modal-title">The Title</h4>
value <input type="text" ng-model="x" />
<button ng-click="close()">Close</button>
</div>
</script>
请在$uibModal.open中定义控制器更多参考请访问此文档详细 https://github.com/angular-ui/bootstrap/tree/master/src/modal/docs
刚刚在 plunker 中测试,$uibModal 需要您的控制器才能绑定到您的范围。
改变;
$scope.open = function(){
$scope.modalInstance = $uibModal.open({
templateUrl: 'myModalContent.html',
scope: $scope
});
};
致;
$scope.open = function(){
$scope.modalInstance = $uibModal.open({
templateUrl: 'myModalContent.html',
scope: $scope,
controller: "ctl"
});
};
如果您使用的是 .js 文件,则应使用 controllerUrl = "path/to/jsfile.js" 加上所述控制器的名称。
这个问题有助于解决 $uibModal onload 事件
刚刚添加到 modalController
$scope.open = function () {
$scope.status.opened = true;
};
$scope.$watch(status, function (newValue, oldValue) {
//code required onload..
});