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');
};
};
Run Code Online (Sandbox Code Playgroud)
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: {{ …Run Code Online (Sandbox Code Playgroud) 我在模态中的模板中有链接.当我单击它们时,当前页面会发生变化,但叠加层和模态会保持不变.我可以添加ng-click="dimiss()"模态中所有模板中的每个链接,但有更好的方法吗?例如,在成功路由更改时自动关闭它,或者ng-click每个模板只添加一个来处理所有链接?
如何检查给定的输入控件是否为空?我知道$pristine场上有一些属性告诉我,如果一个给定的字段最初是空的,但是如果有人填充该字段并再次拉出整个内容呢?
我认为上述功能是必要的,因为它对于告诉用户需要字段非常重要.
任何想法将不胜感激!
我通过以下方式使用Angular-UI typeahead:
<input type="text" ng-model="myModel" typeahead="o.value as o.text for o in options | filter:$viewValue | limitTo:5" typeahead-editable="false" />
Run Code Online (Sandbox Code Playgroud)
绑定到如下模型:
var options = [
{"value": 1, "text": "value1"},
{"value": 2, "text": "value2"},
...
];
Run Code Online (Sandbox Code Playgroud)
它正确显示选项文本,但是当我选择一个项目时,它会在文本框中显示值.模型仅限于值(不是整个模型对象).
是否有可能在选择后在文本框内显示"文本"(而不是"值"),仍然只保持模型绑定到值(即:当我选择某个"文本"时,模型更新为"值" )?
这是我的plnkr:http://plnkr.co/edit/n8cRXwIpHJw3jUpL8PX5?p = preview 你必须点击一个li元素,表格才会出现.输入随机字符串并点击"添加通知".而不是textarea文本,你将得到未定义.
标记:
<ul>
<li ng-repeat="ticket in tickets" ng-click="select(ticket)">
{{ ticket.text }}
</li>
</ul>
<div ui-if="selectedTicket != null">
<form ng-submit="createNotice(selectedTicket)">
<textarea ng-model="noticeText"></textarea>
<button type="submit">add notice</button>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
JS部分:
$scope.createNotice = function(ticket){
alert($scope.noticeText);
}
Run Code Online (Sandbox Code Playgroud)
返回'undefined'.我注意到当使用ui-if of angular-ui时这不起作用.任何想法为什么这不起作用?怎么解决?
我是AngularJS的新手,也很棒.我需要在我的项目中使用Twitter的bootstrap插件.我偶然发现了这两个GitHub项目
现在,我很困惑选择哪一个.这些生产准备好了吗?或者我应该使用Bootstrap附带的jQuery扩展.
我有一个日期存储为SQL Server中的日期.当我在SQL中查询时,日期显示为2014年4月24日.那是正确的.日期以UTC格式正确地转移到客户端.要编辑该日期,我们使用的是Angular UI DatePicker.DatePicker根据我的本地时区调整该日期,因此总是关闭一天.
我可以看到它正在发生.如果我们正在编辑DateTime而不是Date,那么调整时区是正确的.但是,在这种情况下,我只有一个日期,所以我不关心时区,我只想编辑数据库中的日期.
我可以验证它是否正在调整时区.如果我将Windows机器上的时区更改为UTC,则DatePicker会显示正确的日期.
所以,问题是,有没有办法告诉DatePicker关闭时区调整,只管理UTC格式的日期,以便它可以使用SQL Date而不是SQL Datetime?
嗨,我有一个文本区域的characeter计数器.我的问题是它不计算空格或换行符.我该怎么做才能这样做?
<div class="controls">
<textarea rows="4" cols="50" maxlength="1500" data-ng-minLength="1" data-ng
model="createprofilefields.description" required highlight-on-
error></textarea>
<br />
<!--counter-->
<span class="form-help">{{1500-createprofilefields.description.length}}
Characters</span>
</div>
Run Code Online (Sandbox Code Playgroud) angularjs angular-ui angularjs-directive angularjs-ng-repeat
更新:这应该可以在angular-ui-router中使用1.0.0alpha0.请参阅发行说明https://github.com/angular-ui/ui-router/releases/tag/1.0.0alpha0和问题https://github.com/angular-ui/ui-router/issues/1018 I创建.
在处理解决方案时,我想访问应用程序导航到使用角度ui-router的状态名称和其他属性.
原因是:我想在允许应用程序输入该页面之前异步加载一些用户数据(包括其访问权限).
目前这是不可能的,因为将$ state注入解决点指向您正在导航的状态,而不是您要导航到的状态.
我知道我可以:
我还在ui-router github上创建了一个问题(如果你有兴趣,请点击+1):https: //github.com/angular-ui/ui-router/issues/1018
到目前为止,这是我的代码.任何帮助赞赏!
.config(function($stateProvider) {
$stateProvider.state('somePage', {
// ..
resolve: {
userData: function($stateParams, $state, Settings) {
return Settings.getUserData() // load user data asynchronously
.then(function (userData) {
console.log($stateParams);
console.log($state);
// Problem: $state still points to the state you're navigating away from
});
}
}
});
});
Run Code Online (Sandbox Code Playgroud) 有没有办法看到所有已经开启的州$stateProvider?
在这种情况下,我希望我的状态分配分布在许多文件中.我想在不同的文件中run或config在不同的文件中检查构建的状态.
例如:
# component1.coffee
angular.module('zoo').config ($stateProvider) ->
$stateProvider.state 'component1',
url: '/component1'
template: _template
controller: 'Component1Ctrl'
# component2.coffee
angular.module('zoo').config ($stateProvider) ->
$stateProvider.state 'component2',
url: '/component2'
template: _template
controller: 'Component2Ctrl'
# componentNavigation.coffee
angular.module('zoo').run ($state) ->
console.log 'All configured states:', $state.configuredStates # doesn't exist.
Run Code Online (Sandbox Code Playgroud)
有什么东西会列出这两个州,component1并且component2?