小编Dav*_*oro的帖子

测试angularjs指令(更改隔离范围var后模板未在测试中更新)

我正在创建一个angularjs组件,它将(将)提供一个带有过滤,排序,切换选项,滚动等的复选框列表指令......一旦完成.它应该可以帮助人们处理长复选框列表.

我正在尝试按标签或ID功能测试订单,但即使在$ digest或$ apply调用之后,模板也不会反映模型更改.我试图解决但没办法.

这是指令定义:

angular.module('angularjsSmartcheckboxApp')
  .directive('smartCheckbox', [function () {
    return {
      templateUrl: 'views/smartcheckbox.html',
      restrict: 'E',
      replace: true,
      scope: {model: '='},
      controller: ['$scope', '$element', '$attrs', function ($scope, $element, $attrs) {
        // TODO
      }]
    };
  }]);
Run Code Online (Sandbox Code Playgroud)

用法:

<smart-checkbox model="smartList" />
Run Code Online (Sandbox Code Playgroud)

其中smartList是:

$scope.smartList = [
    {id: '001', label: 'First item'},
    {id: '002', label: 'Second item'},
    {id: 'Z01', label: 'Another item'}
  ];
Run Code Online (Sandbox Code Playgroud)

这是模板:

...
<div class="input-group ordercontrols">
  Order options:
  <label class="radio-inline">
    <input type="radio" value="label" ng-model="orderby"> Label
  </label>
  <label class="radio-inline">
    <input type="radio" value="id" ng-model="orderby"> …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angularjs-directive

1
推荐指数
1
解决办法
1703
查看次数