在ui-router内部点击ng-click不激活

时间:2015-06-24 07:38:33

标签: angularjs angular-ui-router angularjs-ng-click

我有一个没有开火的ngClick。

这是我的观点:

<div ng-repeat="(key,val) in user[docParam]">
        {{key}}<input type='text' class="form-control" name="{{key}}" ng-model="user[docParam][key]">
    </div>



    <div class="col-xs-6 col-xs-offset-3" ng-if="nextDoc(docParam)">

        <a ui-sref="form.{{nextDoc(docParam)}}" class="btn btn-block btn-info">
        Proceed To {{nextDoc(docParam)}} &nbsp <span class="glyphicon glyphicon-circle-arrow-right"></span>
        </a>

    </div>
    <div class="col-xs-6 col-xs-offset-3" ng-if="nextDoc(docParam)==false">

        <a ng-click="save(user)" class="btn btn-block btn-info">
        save &nbsp <span class="glyphicon glyphicon-circle-arrow-right"></span>
        </a>

    </div>

这是app.js

var $stateProviderRef = null;
var $urlRouterProviderRef = null;

var app= angular.module('app', [
  //'ui.bootstrap', 
  'ui.router',
  'ui.bootstrap',
  'flow',
  'controllers',
  'services',
  'filters',
  'directives',
  'xeditable',
  'ngResource',
])


.run(['$rootScope', '$state', '$stateParams',
  function($rootScope, $state, $stateParams) {
    $rootScope.$state = $state;
    $rootScope.$stateParams = $stateParams;
  }
])
.controller('AController', ['$scope', function($scope) {} ])
.controller('SController', ['$scope', function($scope) {} ])

.config(['$locationProvider', '$stateProvider', '$urlRouterProvider', '$httpProvider',
    function($locationProvider, $stateProvider, $urlRouterProvider, $httpProvider) {

      // XSRF token naming
      $httpProvider.defaults.xsrfHeaderName = 'x-dt-csrf-header';
      $httpProvider.defaults.xsrfCookieName = 'X-CSRF-TOKEN';

      //$httpProvider.interceptors.push('httpInterceptor');

      $stateProvider
        .state('form', {
          url: "/form",
          templateUrl: '../partials/form/form.html',
          controller:'formController',
        });
      $urlRouterProvider.deferIntercept();

      $urlRouterProvider.otherwise('/form');

      $locationProvider.html5Mode({
        enabled: false
      });
      $stateProviderRef = $stateProvider;
      $urlRouterProviderRef = $urlRouterProvider;

}])

.run(['$q', '$rootScope', '$http', '$urlRouter',
  function($q, $rootScope, $http, $urlRouter) {

    var $state = $rootScope.$state;

    $http
      .get("../lib/modules.json")
      .success(function(data) {


        angular.forEach(data, function(value, key) {

          var getExistingState = $state.get(value.name);

          if(getExistingState !== null){
            return; 
          }

          var state = {
            "url": value.url,
            "parent": value.parent,
            "abstract": value.abstract,
            "views": {}
          };

          angular.forEach(value.views, function(view) {
            state.views[view.name] = {
              templateUrl: view.templateUrl,
              controller:'formController',
            };
          });

          $stateProviderRef.state(value.name, state);

        });
        // Configures $urlRouter's listener *after* your custom listener
$state.go("form.personalInfo");

      });
  }
]);

控制器:

.controller('formController', function($scope,DocParamData,$state,$http) {
     'use strict';


    $scope.docParam = $state.current.name.split('.');
    $scope.docParam = $scope.docParam[1];


    // we will store all of our form data in this object

    $scope.saveUser = function(user) {

   $http.post('/users', user).success(function(v){
        return user;

  }).error(function(err) {
      if(err.field && err.msg) {
        // err like {field: "name", msg: "Server-side error for this username!"} 
        $scope.editableForm.$setError(err.field, err.msg);
  } else { 
    // unknown error
    $scope.editableForm.$setError('name', 'Unknown error!');
      }
    });
  };

问题在于ng-click,它不会触发。甚至没有一个简单的警报。我已经尝试了线程中的所有内容,我不知道出了什么问题。 我记得有一些方法可以让onclick使用范围...但是找不到合适的语法..

1 个答案:

答案 0 :(得分:0)

您可能在控制台中遇到了您不知道的错误。

我非常确定{{...}}指令不支持动态ui-sref表达式语法。请参阅this issue

同样name="{{key}}"应为ng-attr-name="{{key}}"