以上就是给各位分享AngularJS:input[radio]不起作用,其中也会对angularinputdisabled进行解释,同时本文还将给你拓展anglejs–AngularJS:ng-cli
以上就是给各位分享Angular JS:input [radio]不起作用,其中也会对angular input disabled进行解释,同时本文还将给你拓展anglejs – Angular JS:ng-click范围集在ng-if中不起作用、angular – @Input:双向数据绑定不起作用、angular2更改子组件中的@input值然后更改父组件中的此值不起作用、angularjs input type=radio isChecked等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:- Angular JS:input [radio]不起作用(angular input disabled)
- anglejs – Angular JS:ng-click范围集在ng-if中不起作用
- angular – @Input:双向数据绑定不起作用
- angular2更改子组件中的@input值然后更改父组件中的此值不起作用
- angularjs input type=radio isChecked
Angular JS:input [radio]不起作用(angular input disabled)
这是我的代码:
<div ng-controller="TestController"> <input ng-repeat="item in array" ng-model="selected.name" value="{{item.name}}" type="radio"></input></div><script type="text/javascript"> var app = angular.module(''app'', []); app.controller(''TestController'', function ($scope) { $scope.array = [{ name: ''lee'', seq: 1, }, { name: ''tom'', seq: 2, }, { name: ''jack'', seq: 3, }]; $scope.selected = $scope.array[0]; });</script>
显示页面时,默认选中的单选框正确。但这不能取消选中,而我只能在其他两个复选框之间切换吗?我该如何解决这个问题?
答案1
小编典典ng-repeat创建新作用域,因此您应该确定父作用域。
有关更多信息,请参见https://docs.angularjs.org/api/ng/directive/ngRepeat
var app = angular.module(''app'', []); app.controller(''TestController'', function ($scope) { $scope.array = [{ name: ''lee'', seq: 1, }, { name: ''tom'', seq: 2, }, { name: ''jack'', seq: 3, }]; $scope.selected = $scope.array[0].name; });<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><div ng-app="app" ng-controller="TestController"> <div ng-repeat="item in array"> <input type="radio" ng-model="$parent.selected" ng-value="item.name" > </div></div>
anglejs – Angular JS:ng-click范围集在ng-if中不起作用
当您尝试直接在ng点击中设置范围值时,当您的点击是ng – 如果哪个测试具有相同的范围值 – >时,它不起作用. http://jsfiddle.net/9j2TL/26/
angular.module('test',[]) .controller('testCtrl',function($scope) { $scope.step = 1; $scope.setStep = function(step) { $scope.step = step; }; }); <div ng-app="test"> <div ng-controller="testCtrl"> <ul> <li> <div> <buttonng-click="step = 2">Without ngif block</button> </div> </li> <li ng-if="step > 1"> <div> <buttonng-click="step = 3">with ngif block</button> </div> </li> <li ng-if="step > 1"> <div> <buttonng-click="setStep(3)">With ngif block and scope function</button> </div> </li> </ul> <p> step value : {{ step }} </p> </div> </div>
要解决它,你应该创建一个范围函数…
如果有人解释这个问题,我很乐意理解它!
谢谢 :)
Updated Fiddler.
这样做有效:
<li ng-if="step > 1"> <div> <buttonng-click="$parent.step = 3">with ngif block</button> </div> </li>
这正在发生,因为ng-if的内部正在创建一个新的范围.
angular – @Input:双向数据绑定不起作用
================================================== ================
我有这个简单的双向绑定,我正在尝试更新父类和子节点上的字符串属性
问题:当单击“从父级更新”时,两个绑定都会更新.但是当点击“从孩子更新”时,只有孩子更新!
这看起来很简单,我可以做错什么?
(注意:我使用了角度CLI来运行项目)
================================================== ================
父组件:
import { Component,OnInit } from '@angular/core'; @Component({ selector: 'app-my-dad',templateUrl: './my-dad.component.html',styleUrls: ['./my-dad.component.css'] }) export class MyDadComponent { parentModel: string; constructor() {} updateModel(){ this.parentModel += ' parent'; } }
父模板
<h2>Parent: {{ parentModel }} </h2> <button (click)="updateModel()"> update from parent </button> <app-my-child [(model)]="parentModel"></app-my-child>
儿童组件
import { Component,OnInit,Input } from '@angular/core'; @Component({ selector: 'app-my-child',templateUrl: './my-child.component.html',styleUrls: ['./my-child.component.css'] }) export class MyChildComponent { @input() model: string; constructor() { } updateModel(){ this.model += ' child'; } }
儿童模板:
<h2>Child: {{ model }} </h2> <button (click)="updateModel()"> update from child </button>
@input() myProp:String; @Output() myPropChange:EventEmitter<String> = new EventEmitter<String>;
另见https://angular.io/docs/dart/latest/guide/template-syntax.html#!#two-way
要使用ngModel进行双向绑定,您的组件需要实现ControlValueAccessor
也可以看看
> https://angular.io/docs/ts/latest/api/forms/index/NgModel-directive.html
> https://github.com/angular/angular/issues/11073#issuecomment-242563788
angular2更改子组件中的@input值然后更改父组件中的此值不起作用
export class Parent { show: boolean = false; constructor() { } showChild() { this.show = true; } }
父组件模板
<child [isShow]="show"></child>
子组件类
export class Child { @Input isShow: boolean = false; constructor() { } onClick() { this.isShow = false; } }
在我触发子组件中的onClick()后,showChild()无法显示子组件.
为什么?
为了使值双向,您需要使用双向数据绑定.
这意味着你的isShow属性应该是这样的:
@input() isShow: boolean; @Output() isShowChange = new EventEmitter<boolean>();
模板应该是
<child [(isShow)]="show"></child>
要么
<child [isShow]="show" (isShowChange)="show = $event"></child>
看一下双向数据绑定教程页面:
https://angular.io/guide/template-syntax#two-way-binding—
angularjs input type=radio isChecked
1、html:2、js:
关于Angular JS:input [radio]不起作用和angular input disabled的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于anglejs – Angular JS:ng-click范围集在ng-if中不起作用、angular – @Input:双向数据绑定不起作用、angular2更改子组件中的@input值然后更改父组件中的此值不起作用、angularjs input type=radio isChecked的相关知识,请在本站寻找。
本文标签: