AngularJS ngModel指令的选择 [英] AngularJS ngModel directive in select

查看:158
本文介绍了AngularJS ngModel指令的选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个angularjs项目和我有同样的概念在另一选择标记,在工作select.But在 ngModel 没有约束力问题同样的html页面。
下面是code。

I am working on an angularjs project and i have a problem with the ngModel not binding within the select.But the same concept is working in another select tag and in the same html page. Below is the code.

  <select ng-model="selectedFont" 
          ng-options="font.title for font in fonts" 
          ng-change="onFontChange()">
  </select>

onFontChange()功能被放置在控制器中。

onFontChange() function is placed in the controller.

任何人的帮助是非常AP preciable ...在此先感谢。

Anyone help is highly appreciable...Thanks in advance.

推荐答案

根据托尼小马的小提琴:

Based on Tony the Pony's fiddle :

<div ng-app ng-controller="MyCtrl">
    <select ng-model="opt"
            ng-options="font.title for font in fonts"
            ng-change="change(opt)">
    </select>

    <p>{{opt}}</p>
</div>

通过控制器:

function MyCtrl($scope) {
    $scope.fonts = [
        {title: "Arial" , text: 'Url for Arial' },
        {title: "Helvetica" , text: 'Url for Helvetica' }
    ];
    $scope.change= function(option){
        alert(option.title);
    }
}

http://jsfiddle.net/basarat/3y5Pw/43/

这篇关于AngularJS ngModel指令的选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆