AngularJS中的范围问题使用AngularUI Bootstrap Modal
发布时间:2020-12-17 09:01:49 所属栏目:安全 来源:网络整理
导读:plunker: http://plnkr.co/edit/wURNg8ByPYbEuQSL4xwg example.js: angular.module('plunker',['ui.bootstrap']); var ModalDemoCtrl = function ($scope,$modal) { $scope.open = function () { var modalInstance = $modal.open({ templateUrl: 'modal.h
plunker:
http://plnkr.co/edit/wURNg8ByPYbEuQSL4xwg
example.js: angular.module('plunker',['ui.bootstrap']); var ModalDemoCtrl = function ($scope,$modal) { $scope.open = function () { var modalInstance = $modal.open({ templateUrl: 'modal.html',controller: 'ModalInstanceCtrl' }); }; }; var ModalInstanceCtrl = function ($scope,$modalInstance) { $scope.ok = function () { alert($scope.text); }; $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; }; index.html: <!doctype html> <html ng-app="plunker"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.js"></script> <script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.6.0.js"></script> <script src="example.js"></script> <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet"> </head> <body> <div ng-controller="ModalDemoCtrl"> <button class="btn" ng-click="open()">Open me!</button> <div ng-show="selected">Selection from a modal: {{ selected }}</div> </div> </body> </html> modal.html: <div class="modal-header"> <h3>I'm a modal!</h3> </div> <textarea ng-model="text"></textarea> <div class="modal-footer"> <button class="btn btn-primary" ng-click="ok()">OK</button> <button class="btn btn-warning" ng-click="cancel()">Cancel</button> </div> 为什么我不能得到$ scope.text在ModalInstanceCtrl中定义,即使我可以使用$ scope.ok和$ scope.cancel?
看起来像一个范围问题。我得到它工作这样:
var ModalInstanceCtrl = function ($scope,$modalInstance) { $scope.input = {}; $scope.ok = function () { alert($scope.input.abc); }; $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; }; HTML: <textarea ng-model="input.abc"></textarea> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- angularjs – 使用angular指令来改变ng-repeat元素的类
- bash – 递归触摸修复计算机之间的同步
- bash脚本错误[:!=:一元运算符
- Scala和Play框架2.2.0,Action.async和isAuthenticated
- Docker撰写错误“在文件’./docker-compose.yml’中,服务’
- angular路由小结
- Bootstrap模态窗口源码解析
- /etc/profile,/etc/bashrc,~/.bash_profile,~/.bashrc
- 详解Bootstrap的aria-label和aria-labelledby应用
- Bootstrap js插件使用大全