Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Angularjs ui-select在指令中使用大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在我的cusom指令里面使用angular-ui ui-SELEct指令叫做timezone.问题是当从列表中选择时区时,不会更新周围控制器的模型对象.
这是我的指令代码: @H_403_8@

@H_403_8@

var myApp = angular.module('MyApp',['ui.SELEct','ngSanitize']);

myApp.directive('timezone',function () {
return {
    reStrict: 'AE',template: '<ui-SELEct theme="bootstrap" ng-model="tzModel" style="min-width: 300px;"> <ui-SELEct-match placeholder="SELEct a timezone in the list">{{$SELEct.SELEcteD}}</ui-SELEct-match> <ui-SELEct-choices repeat="tz in timezones | filter: $SELEct.search"> <div ng-bind-html="tz"></div> </ui-SELEct-choices> </ui-SELEct>',scope: {
        tzModel : '=',},link: function(scopE) {
        scope.timezones = ["Africa/Abidjan","UTC"];
    }
};
});
@H_403_8@我的控制器:

@H_403_8@

@H_931_8@myApp.controller('MyCtrl',function ($scope) { $scope.foo = {name:"Africa/Abidjan"}; }); @H_403_8@这是我在html中使用它的方式:

@H_403_8@

<div ng-app="MyApp" ng-controller="MyCtrl">
  {{foo}}<br />
  <timezone tz-model="foo.name" />
</div>
@H_403_8@问题是,当我从下拉列表中选择一个新值时,我的控制器对象不会更新.
Here is the jsFiddle
我猜ui-SELEct存在问题,因为我已经完成了与其他组件相同的工作.

@H_674_22@解决方法
您需要在ui-SELEct指令中设置ng-model =“tzModel.name”. @H_403_8@

@H_403_8@https://github.com/angular-ui/ui-select/wiki/FAQs#ng-model-not-working-with-a-simple-variable-on-scope

@H_403_8@

<timezone tz-model="foo" />

<ui-SELEct theme="bootstrap" ng-model="tzModel.name" ...
@H_403_8@https://jsfiddle.net/XyUGE/264/

大佬总结

以上是大佬教程为你收集整理的Angularjs ui-select在指令中使用全部内容,希望文章能够帮你解决Angularjs ui-select在指令中使用所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。