我已经设置了一个json,其中包含附有ID和国家/地区代码的国家/地区列表:
它看起来像这样:
$scope.countries = [
{"name":"Afghanistan","id":"AFG","country-code":"004"},
{"name":"Åland Islands","id":"ALA","country-code":"248"},
{"name":"Albania","id":"ALB","country-code":"008"},
{"name":"Algeria","id":"DZA","country-code":"012"}
]
Run Code Online (Sandbox Code Playgroud)
然后我使用该ng-repeat指令为每个国家/地区创建复选框输入.
<div ng-repeat="country in countries">
<label><input type="checkbox" ng-model="{{country.id}}" ng-true-value="'{{country.name}}'" ng-false-value="''">{{country.name}}</label>
</div>
Run Code Online (Sandbox Code Playgroud)
但是,当我运行代码时,我只显示以下内容:
位置复选框 {{country.name}}
如果我删除ng-model重复的部分我的复选框生成正常但我需要一个唯一的ng-model附加到每个复选框
ng-model="{{country.id}}"
Run Code Online (Sandbox Code Playgroud)
我如何附加一个独特的ng-model价值?
这个答案(在ng-repeat中生成ng-model)不提供唯一ng-model值
我在我的角度应用程序中设置了以下内容
我有一个图像,其中ng-mouseover和ng-mouseleave事件与图像标记相关联
<img ng-mouseover="infoIconStyle={'height':'50px','padding':'10px'}" ng-mouseleave="infoIconStyle={'height':'0','padding':'0'}" src="images/info-icon.svg" />
Run Code Online (Sandbox Code Playgroud)
然后将这些鼠标悬停事件发送到以下div
<div class="dataBoxInfoContent" ng-style="infoIconStyle">{{description}}</div>
Run Code Online (Sandbox Code Playgroud)
因此,当触发ng-mouseover时,dataBoxInfoContent div会因高度从0到50px而打开,并且当触发ng-mouseleave时div再次关闭.
但是由于某些原因,当鼠标离开图像时,触发了鼠标左键,而这只是在谷歌浏览器中.一切正常,在Internet Explorer和Mozilla Firefox中.
任何人都知道为什么会这样吗?
我正在使用ngRepeat生成一个复选框的字段集.
我这样做如下:
<fieldset id="country_select" ng-controller="CountriesListController">
<span ng-repeat="country in countries">
<label>
<input type="checkbox" id="country.name" ng-change="locationAdd(country.name)">
{{country.name}}
</label><br/>
</span>
</fieldset>
Run Code Online (Sandbox Code Playgroud)
但是由于某种原因,将ngChange指令添加到我的复选框会导致我的ng-repeat输出只显示一个复选框,如下所示:
复选框 {{country.name}}
当我将ngChange更改为ngClick时,我的ngRepeat循环正常工作.
所以我的问题是:为什么ngChange不适用于ngRepeat,但ngClick插入我的复选框输入时会这样做
我在控制台中收到以下错误:
Error: [$compile:ctreq] Controller 'ngModel', required by directive 'ngChange', can't be found!
http://errors.angularjs.org/1.3.7/$compile/ctreq?p0=ngModel&p1=ngChange
at REGEX_STRING_REGEXP (http://localhost:9000/bower_components/angular/angular.js:63:12)
at getControllers (http://localhost:9000/bower_components/angular/angular.js:7535:19)
at nodeLinkFn (http://localhost:9000/bower_components/angular/angular.js:7724:33)
at compositeLinkFn (http://localhost:9000/bower_components/angular/angular.js:7073:13)
at compositeLinkFn (http://localhost:9000/bower_components/angular/angular.js:7076:13)
at compositeLinkFn (http://localhost:9000/bower_components/angular/angular.js:7076:13)
at publicLinkFn (http://localhost:9000/bower_components/angular/angular.js:6952:30)
at $get.boundTranscludeFn (http://localhost:9000/bower_components/angular/angular.js:7091:16)
at controllersBoundTransclude (http://localhost:9000/bower_components/angular/angular.js:7747:18)
at ngRepeatAction (http://localhost:9000/bower_components/angular/angular.js:24524:15)angular.js:11592 (anonymous function)angular.js:8542 $getangular.js:14241 $get.Scope.$digestangular.js:14486 $get.Scope.$applyangular.js:9644 doneangular.js:9834 completeRequestangular.js:9775 requestLoaded
Run Code Online (Sandbox Code Playgroud) XAML,C#新手,我正努力将我的代码中定义的变量数据绑定到XAML中定义的文本块.但我得不到结果.
这是我的XAML
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
Loaded="Window_Loaded_1">
<Grid>
<TextBlock Name="totalRecording">
<Run Text="44 /"/>
<Run Text="{Binding Source=listlength, Path=totalRecording}"/>
</TextBlock>
</Grid>
Run Code Online (Sandbox Code Playgroud)
这是我背后的代码
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded_1(object sender, RoutedEventArgs e)
{
var listlength = 100;
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我只是为了说明我的问题而将变量设置为静态数字,但是这个变量将从列表Count值中获得.
我正在构建一个WPF应用程序.XAML用于前端,C#用于代码
我有以下代码段,动态地为我生成我的XAML.
if (station_item.Checker_Setup.First().Checker_Log.OrderByDescending(log => log.date).First().Status.status_key == 2)
{
Path path = new Path();
path.Data = new RectangleGeometry(new Rect(0, 0, 19, 21), 3, 3);
path.Style = "{StaticResource statusIndicatorRed}";
TextBlock block = new TextBlock();
block.Text = station_item.station_name;
WrapBox.Children.Add(path);
WrapBox.Children.Add(block);
}
Run Code Online (Sandbox Code Playgroud)
但是我有
path.Style = "{StaticResource statusIndicatorRed}";
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
无法将String类型隐式转换为System.Windows.Style
样式在我的MainWindow.xaml中定义如下
<Style x:Key="statusIndicatorRed" TargetType="Path">
<Setter Property="Fill" Value="#B2203D" />
<Setter Property="Width" Value="19px" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="ToolTipService.ShowDuration" Value="30000" />
<Setter Property="Cursor" Value="Help" />
</Style>
Run Code Online (Sandbox Code Playgroud)
我如何在我的代码背后传递这种风格?这甚至是做事的好方法吗?
我已决定使用vanilla javascript创建淡入淡出的动画效果.
这是我淡入效果的代码:
document.querySelector('.open-1_1').onclick = function() {
document.getElementById('about-frame').style.display = 'block';
for (opacity = 0; opacity < 1.1; opacity = opacity + 0.1)
{
setTimeout(function(){document.getElementById('about').style.opacity = opacity;},100)
}
};
Run Code Online (Sandbox Code Playgroud)
我想要做的是通过运行for循环逐步增加#about div的不透明度从0到1,对于循环的每次迭代,该循环应该等待100毫秒
但是#about div在一段时间之后从黑暗变为不透明度1而没有看到淡入效果.
我的逻辑出了什么问题?