如何将模板 url 添加到 codeigniter 中的自定义指令

How to add template url to custom directives in codeigniter

我想在 angular 自定义指令中加载视图文件作为模板。我的指令代码

我想知道使用 angularjs 在 codeigniter 中使用模板的正确方法。 如果需要更多信息,请告诉我。这是我对这个网站的第一个问题..谢谢

我的厨师控制器

class Cooks extends MX_Controller {


    /**
     * Renders an angular view.
     * @param string $pageName
     */
    function getpage($pageName){
             $this->load->view($pageName);
      }

}

路由

$route['cooks/getPage/(:any).html']='cooks/getPage/';

指令

app.directive('profileSettings',function () {
      return {
        restrict: 'E',
        require:'ngModel',
        templateUrl: 'cooks/getPage/profileSettings',

      }
  });

假设您有一个名为 Ng_pages 的控制器。这个控制器有一个 index 方法,它接受一个参数 - $pageName.

class Ng_pages extends CI_Controller
{

    /**
     * Renders an angular view.
     * @param string $pageName
     */
    public function index($pageName)
    {
        // put here the code to check whether the requested page exists
        // and load the requested view
        $this->load->view($pageName);
    }

}

以及控制器的路由规则:

$route['ng-pages/(:any).html'] = 'Ng_pages/index/';

您还需要在指令中更改 templateUrl。请注意,您可能需要设置绝对 url.

templateUrl: 'ng-pages/profileSettings.html'